Configure the Proxy Server
Learn how to install and configure NGINX with Heroku.
We'll cover the following...
Installing NGINX
NGINX is not a Python package, so it can’t be inferred from the Pipfile. Instead, we need to explicitly tell Heroku to install it using the buildpack.
$ heroku buildpacks:add heroku-community/nginx
NGINX configuration
The easiest way to set up NGINX is to serve files from a directory. However, that’s not going to be good enough here, so we need to look into customizing its configuration file. We’ll put our NGINX and Gunicorn configuration files in a new config directory at the top of the Git repository. When requests first come in, they’ll go to NGINX, so we’ll look at the nginx.conf.erb file first. Here it is, in its entirety:
The main thing to recognize is that there are two main blocks. In the events block, NGINX is set up appropriately for the size and OS of the virtual machines it will be running on. It should be able to handle 1024 simultaneous connections per worker, and there should be one worker per CPU core. Typically, a browser uses two connections, so this setup should support about 2000 simultaneous users. That’s a lot! ...