Reverse Proxy With Nginx

Environment :
Linux/Debian 9.2

# apt-get update
# apt-get -y install vim-nox curl wget dnsutils nginx
# rm  /etc/nginx/sites-enabled/default
# vim /etc/nginx/conf.d/upstream.conf

upstream backoriginal {
	server			srv1.truedigitalplus.com:80;
	server			srv2.truedigitalplus.com:80;
}

# vim /etc/nginx/sites-available/frontend.conf

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	
	server_name frontapp;
	set $proxy_backend_host truedigitalplus.com;
	location / {
		proxy_pass              http://backoriginal;
		proxy_set_header        Host                    $proxy_backend_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_set_header        Accept-Encoding         "";

		sub_filter_types *;
		sub_filter "http://$proxy_backend_host/" "http://$host/";
		sub_filter "$proxy_backend_host/" "$host/";
		sub_filter "$proxy_backend_host" "$http_host";
		sub_filter_once off;

		proxy_redirect ~(^http://www.$proxy_backend_host|^)/(.*)$ http://$host/$2;
		proxy_redirect ~(^http://$proxy_backend_host|^)/(.*)$ http://$host/$2;
	}
}

# cd /etc/nginx/sites-enabled/
# ln -sf ../sites-available/frontend.conf

# /etc/init.d/nginx restart
# systemctl enable nginx

# shutdown -r now

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.