Linux: NGINX: Proxy reverse

PHOTO EMBED

Mon Aug 29 2022 14:02:30 GMT+0000 (UTC)

Saved by @marcopinero #bash

# NGINX: add <folder> in /etc/nginx/sites-available/default: 

server {
    :
    location /<folder>/ {
        proxy_pass http://<host>:<port>/;
        proxy_set_header X-Original-Host $http_host;
        proxy_set_header X-Original-Scheme $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
    :
}
    
# APACHE2: add <folder> in /etc/apache2/sites-available/00-default.conf

<VirtualHost *:80>
    :
        ProxyPass /<folder> http://<host>:<port>/
        ProxyPassReverse /<folder> http://<host>:<port>/

        ProxyRequests Off
        ProxyPreserveHost On

        <proxy>
            Order deny,allow
            Allow from all
        </proxy>
    :
</VirtualHost>


#examples: folder "http://192.168.11.45/demo -> http://192.168.11.45:8080/"

server {
    :
    location /demo/ {
        proxy_pass http://localhost:8080/;
        proxy_set_header X-Original-Host $http_host;
        proxy_set_header X-Original-Scheme $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
    :
}

<VirtualHost *:80>
    :
        ProxyPass /demo http://localhost:8080/
        ProxyPassReverse /demo http://localhost:8080/

        ProxyRequests Off
        ProxyPreserveHost On

        <proxy>
            Order deny,allow
            Allow from all
        </proxy>
    :
</VirtualHost>

/* other configuration for nginx:
    
server {
    listen        80;
    server_name   example.com *.example.com;
    location / {
        proxy_pass         http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}
*/
content_copyCOPY

Proxy reverse: let you point web folders to other server/ports.