Configuring NGINX
NGINX is a powerful HTTP proxy server you can use to direct traffic to its appropriate destination, apply routing rules, or even implement caching. We start with a Dockerfile that’ll allow us to create a NGINX image with our ownnginx.conf configuration file:
server_name directive says which hostname the server directive will be handling and the location directive uses proxy_pass to send all requests on to the appropriate site.
Deploying NGINX to Fly
We now need to create a slot for our new Fly app. Assuming you are signed up and logged in (if not see our hands-on for getting started), then we’ll run this:nginxproxy but we recommend you use the autogenerated name to ensure a unique name. As well as creating the slot for the app in the Fly infrastructure, a fly.toml file will be created with the app name and configuration settings in it. To deploy our NGINX, we literally issue the deploy command:
flyctl status. You’ll see it has a hostname which you can use to connect. The host name will match none of the hosts in the nginx.conf file and so it will proxy for the default server - the first server listed in that configuration file.