I have the following setup
- Master server - call it
https://master.com - Slave server - call it
https://slave.com
Both run Nginx on Ubuntu 16.04
On the master server I have created the following configuration block in my /etc/nginx/sites-available/default file
location /test
{
rewrite ^/test(.*) /$1 break;
proxy_pass https://slave.com;
proxy_read_timeout 240;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
A service nginx reload later on master.comand I can do the following
- Browse to
https://master.com/testand view the output fromslave.com\index.php. - Browse to
https://master.com/test/test.txtand see the text in the fileslave.com\test.txt - Browse to
https://master/com/test/test.jpgand see the image in the fileslave.com\test.jpg.
However, I cannot do any of the following
- Browse to
https://master.com/test/test.phpwhich instead of showing me the output fromhttps://slave.com/test.phpshows me a 404 error message - Browse to
https://master.com/test/adminer/adminer.phpwhich instead of showing me the login screen for the Adminer instance on the slave,https://slave.com/adminer/adminer.phpshows me the login screen for the Adminer instance onmaster.comi.e.https://master.com/adminer/adminer.php
This is clearly because I am missing something in my Nginx configuration on master.com. However, I am unable to see what that might be.
In the interests of completeness, here is my configuration on both servers:
Ubuntu - 16.04.3 Nginx - 1.10.3 PHP - 7.0.22
I should explain why the ^~ is required since this is not clear from my original question. I have another block setup to handle PHP scripts on master.com.
location ~ \.php$
{
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Because of the way Nginx processes these directives this block takes priority when it comes to handling .php files and master.com ends up looking locally for .php scripts that are actually on slave.com. The only way to avoid this is to use ^~