Ubuntu 20.04
Sponsored Link

Nginx : Reverse Proxy
2020/08/28
 
Configure Nginx as a Reverse Proxy Server.
For example, Configure Nginx that HTTP/HTTPS accesses to [www.srv.world] are forwarded to [dlp.srv.world].
[1]
[2] Configure Nginx.
root@www:~#
vi /etc/nginx/sites-available/default
# change content like follows

# replace server name or certificates to yours


server {
        listen      80 default_server;
        listen      [::]:80 default_server;
        listen      443 ssl http2 default_server;
        listen      [::]:443 ssl http2 default_server;
        server_name www.srv.world;

        ssl_certificate "/etc/letsencrypt/live/www.srv.world/fullchain.pem";
        ssl_certificate_key "/etc/letsencrypt/live/www.srv.world/privkey.pem";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;

        proxy_redirect      off;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    Host $http_host;

        location / {
                proxy_pass http://dlp.srv.world/;
        }
}

root@www:~#
systemctl restart nginx

[3] Configure backend Nginx server to log X-Forwarded-For header.
root@dlp:~#
vi /etc/nginx/nginx.conf
# add [log_format] setting into [http] section


http {
        log_format main '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';

root@dlp:~#
vi /etc/nginx/sites-available/default
# add into [server] section

# specify your local network for [set_real_ip_from]

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        set_real_ip_from   10.0.0.0/24;
        real_ip_header     X-Forwarded-For;

root@dlp:~#
systemctl restart nginx

[4] Verify it works fine to access to frontend Nginx Server from any Client Computer.
Matched Content