Personal documentation

Nginx Reverse Proxy

Install nginx

apt update
apt install nginx

Unlink the default site

unlink /etc/nginx/sites-enabled/default

Create a new config and edit it

touch /etc/nginx/sites-available/reverse-proxy.conf
vim /etc/nginx/sites-available/reverse-proxy.conf

Paste in the config example

server {
        listen 80;
        listen [::]:80;

        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;

        location / {

Create a symb link

ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf

Restart nginx

systemctl restart nginx

ssl example

server {
        listen 80;
        return 301 https://$host$request_uri;

server {

        listen 443 ssl;

        server_name www.example.com;

        ssl_certificate /etc/nginx/ssl/cert.crt;
        ssl_certificate_key /etc/nginx/ssl/cert.key;
        ssl_session_cache builtin:1000 shared:SSL:10m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;

        location / {
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_pass http://localhost:3000;
                proxy_read_timeout 90;
                proxy_redirect http://localhost:3000 https://www.example.com;
Last updated on 13 Nov 2021
Published on 13 Nov 2021