diff --git a/content/2.reference/6.workflow/6.NGINX-reverse-proxy.md b/content/2.reference/6.workflow/6.NGINX-reverse-proxy.md index c0a79bb..cfed32f 100644 --- a/content/2.reference/6.workflow/6.NGINX-reverse-proxy.md +++ b/content/2.reference/6.workflow/6.NGINX-reverse-proxy.md @@ -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). @@ -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/; } } @@ -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: @@ -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.