I give below an execerpt of of /etc/nginx/sites-available/default file
server {
listen 443 ssl;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ = 404;
}
location /rproxy/ {
proxy_pass https://example.org:8144/;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
....
}
The example.org:8144 server
has the files and
index.php - returns hello Worldbonjour.php - returns bonjourNow here is the issue:
If I browse to https://example.com/rproxy it promptly returns hello world - the expected result.
However, if I browse to https://example.com/rproxy/bonjour.php (or even https://example.com/rproxy/index.php) I get a 404 error.
I understand what is happening here. My Nginx configuration is causing the example.com instance of Nginx to attempt to find all *.php files locally (i.e. on example.com) which fails when the file I am seeking is in fact on example.org:8144.
I imagine that there is a relatively simple way to tell Nginx when NOT to attempt to attempt to execute a PHP file - when it is in fact on rproxy. However, my knowledge of Nginx confugration is too limited for me to be able to figure out just how I alter the configuration. I'd be most obliged to anyone who might be tell me how to change the configuration to prevent this from happening.
I should clarify something here:
I need to be able to run PHP scripts on Both SERVERS example.com and example.org.
There is a very easy workaround here - I use a different extension, say php5, for php scripts on the proxied server, example.org. However, that is easily liable to lead to unforseen problems.
For nginx regexp locations have bigger priority than prefix locations. But
If the longest matching prefix location has the “^~” modifier then regular expressions are not checked.
So try to replace
location /rproxy/ {
with
location ^~ /rproxy/ {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With