Skip to content

Setup Reverse Proxy (NGINX)

As a reverse proxy, we will use . Create a new folder called nginx with the following structure and files:
nginx/
├ nginx.conf
├ sites-available
│ └ fdp.conf
└ sites-enabled
└ fdp.conf -> ../sites-available/fdp.conf

Start by creating the folders using the following commands.
sudo mkdir /var/www/fdp/nginx
sudo mkdir /var/www/fdp/nginx sites-available sites-enabled

The file nginx.conf is the configuration of the whole nginx, and it includes all the files from sites-enabled which contains configuration for individual servers (we can use one nginx, for example, to handle multiple servers on different domains). All available configurations for different servers are in the sites-available, but only those linked to sites-enabled are used.
For nginx.conf run the following command,
sudo nano /var/www/fdp/nginx/nginx.conf
...then add the following file content
# nginx/nginx.conf
user www-data www-data;
worker_processes 5;

events {
worker_connections 4096;
}

http {
# Docker DNS resolver
# We can then use docker container names as hostnames in other configurations
resolver 127.0.0.11 valid=10s;

# Include all the configurations files from sites-enabled
include /etc/nginx/sites-enabled/*.conf;
}

Next, enter the following code on your terminal
sudo nano /var/www/fdp/nginx/sites-available/fdp.conf
.. and add the following file contents in the fdp.conf
# nginx/sites-available/fdp.conf
server {
listen 443 ssl;

ssl_certificate /etc/letsencrypt/live/<your-domain.com>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<your-domain.com>/privkey.pem;

server_name <your_domain>;

# Location for FDP (all other requests)
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
proxy_pass http://fdp-client;
}
}

# We redirect all request from HTTP to HTTPS
server {
listen 80;
server_name <your-domain.com>;
return 301 https://$host$request_uri;
}

Finally, we need to create a soft link from sites-enabled to sites-available for the FDP configuration.
cd nginx/sites-enabled && ln -s ../sites-available/fdp.conf

Finally, proceed to

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.