Skip to content

Commit

Permalink
basepath
Browse files Browse the repository at this point in the history
  • Loading branch information
PGimenez committed Oct 27, 2023
1 parent 19f0b51 commit e28e7e6
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions content/2.reference/6.workflow/6.NGINX-reverse-proxy.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
---
title: NGINX reverse proxy
title: Reverse proxy
description: How to use NGINX as a reverse proxy to serve multiple Genie apps and improve performance.
---

# NGINX reverse proxy
## Configuring the app

If you need to run multiple apps from a single domain or subdomain, you can use a reverse proxy to redirect traffic to the appropriate app. For instance, say you want to serve your Genie app at `test.com/genieapp`. To make this work, you'll need to set the base URL path with the environment variable `BASEPATH`. This can be done in the REPL with

```julia
ENV["BASEPATH"] = "/genieapp"
using GenieFramework; Genie.loadapp(); up();
```
or in the terminal with
```sh
export BASEPATH="/genieapp" julia --project -e "using GenieFramework; Genie.loadapp(); up(async=false);"
```

Then, you can proceed to configure the reverse proxy.

## NGINX reverse proxy

When used as a reverse proxy, NGINX will listen requests made on port 80 (HTTP) and redirect traffic to the Genie app running on port 8000 (default Genie setting that can be changed).

Expand Down Expand Up @@ -33,17 +48,7 @@ server {
root /home/ubuntu/MyGenieApp/public;
index welcome.html;

location / {
proxy_pass http://localhost:8000/;
}

location /css/genie {
proxy_pass http://localhost:8000/;
}
location /img/genie {
proxy_pass http://localhost:8000/;
}
location /js/genie {
location /genieapp/ {
proxy_pass http://localhost:8000/;
}
}
Expand All @@ -52,7 +57,6 @@ server {
- `server_name`: refers to the web domain to be used. It can be put to an arbitrary name if the app is only to be served directly from the server public IP.
- `root`: points to the `public` subfolder where the genie app was cloned.
- `index`: refers to the site index (the landing page).
- The various `location` following the initial proxy to the genie app are used to indicate static content folders to be served by nginx. These are needed when the `server_handle_static_file` is set to `false` in the Genie app settings.

To enable the reverse proxy, add the config file to the `sites-enabled` with a symlink:

Expand All @@ -66,6 +70,24 @@ Then restart the server to make changes effective:
sudo systemctl restart nginx
```

## Serving static assets through NGINX

To improve performance, it is recommended that static assets are served by NGINX. To do so, define locationsto indicate static content folders to be served by NGINX.

```
location /css/genie {
proxy_pass http://localhost:8000/;
}
location /img/genie {
proxy_pass http://localhost:8000/;
}
location /js/genie {
proxy_pass http://localhost:8000/;
}
```

These locations are needed when the `server_handle_static_file` is set to `false` in the Genie app settings.

## Enabling HTTPS

To enable HTTPS, a site-certificate will be needed for the domain on which the site will be served.
Expand Down

0 comments on commit e28e7e6

Please sign in to comment.