Reverse proxy help.

Robert Sawyer rlsawyer at mac.com
Wed Sep 15 21:36:54 UTC 2021


I am new to nginx so please be patient, if this info is available elsewhere please tell me where.

I have 3 nginx servers. 1 is used as a reverse proxy and that is where my question is. 
I have 2 web sites running on my home network. I have configured the DNS to refer the site names to my (fixed) home address. I have configured my home modem/router to forward port 80 to the machine running the nginx reverse proxy. I have made scripts in the sites-available on the reverse proxy with the names of the sites I wish to proxy, configured thus:
wordpress1.org.conf
server {
	listen 80;
	server_name wordpress1.org www.wordpress1.org;

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

	location / {
	proxy_pass http://10.111.111.31;

	
	proxy_set_header Upgrade           $http_upgrade;
 	proxy_set_header Connection        "upgrade";
#    	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_set_header X-Forwarded-Host  $host;
 	proxy_set_header X-Forwarded-Port  $server_port;
	}
wordpress2.com.conf
server {
	listen 80;
	server_name wordpress2.com www.wordpress2.com;

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

	location / {
	proxy_pass http://10.111.111.32;

	
	proxy_set_header Upgrade           $http_upgrade;
 	proxy_set_header Connection        "upgrade";
#    	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_set_header X-Forwarded-Host  $host;
 	proxy_set_header X-Forwarded-Port  $server_port;
	}

I have commented out the "proxy_set_header Host              $host;” because with it I get “too many redirects”.

This seems to be working.

I want to have the configuration have a “ name not found” where it goes to the proxy server itself and can display a web page an error or a php page defined by the query string if there is one. I.E. if someone tries to simply access the external IP present an error or if there is a known page that exists on the proxy server ( I have a php page with a known name that displays phpinfo for validating server info) display it, do not proxy. curently if I simply use the IP it displays the server for wordpress2. ( the actual names for the sites wordpress2 is alphebetically first ) so basically how do I make the webpages on the proxy server the “fallback” web server ?


More information about the nginx mailing list