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 {

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

server {
	listen 80 default_server;
	listen [::]:80 default_server;
	server_name frontapp;
	set $proxy_backend_host;
	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: Logo

You are commenting using your 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.