So a little background. I'm in the process of moving website from old servers with Apache to new Ubuntu Servers with NGINX proxy to Apache. There will be a transition period where the website codebase will be running on both old and new servers.
The website has search URLS with filters which are separated by slashes and are often optional e.g
www.example.com/search/deals/q1/q2/q3/q4/q5/q6/
which maps to the following apache.conf rewrite rule:
RewriteRule ^/search/deals/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/ /results.php?q1=$1&q2=$2&q3=$3&q4=$4&q5=$5&q6=$6 [L,QSA]
It is not unusual to have URLs like below
www.example.com/search/deals/q1////q5/q6/
www.example.com/search/deals/q1/q2/q3///q6/
www.example.com/search/deals/q1/q2/q3/q4///
On the new server I have configured NGINX like so: two sites enabled a default server apache file and example.com file
/etc/nginx/sites-enabled/apache -> ../sites-available/apache
/etc/nginx/sites-enabled/example.com -> ../sites-available/example.com
apache looks like so (real IP replaced with 10.10.10.10) :
server {
listen 10.10.10.10:80 default_server;
merge_slashes off; #have tried with/without
location / {
proxy_redirect off; #have tried with/without
port_in_redirect off; #have tried with/without
proxy_pass http://10.10.10.10:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
example.com looks like so
server {
listen 10.10.10.10:80 ;
server_name example.com www.example.com;
root /var/www/live/example.com/frontend/htdocs;
merge_slashes off;
location / {
fastcgi_pass unix:/var/run/php5-fpm.sock; #have tried with/without
include fastcgi_params; #have tried with/without
proxy_redirect off; #have tried with/without
port_in_redirect off; #have tried with/without
proxy_pass http://10.10.10.10:8080 ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#have tried with/without
proxy_set_header X-Accel-Internal /internal-nginx-static-location; #have tried with/without
access_log off;
}
}
After making any change I have restarted NGINX via
service nginx restart
When I load page e.g www.example.com/search/deals/q1/q2////q6/ I get 'file not found' and Then look at the Apache log with Log Level set to 3 I get below:
[Wed Oct 07 22:52:10.178436 2015] [rewrite:trace1] [pid 4186:tid 123456789] mod_rewrite.c(468): [client 10.10.10.10:33468] 10.10.10.10 - - [www.example.com/sid#sddsaddsa][rid#sddsaddsa/subreq] pass through /search/deals/q1/q2/q5/
Which indicates all multiple slashes have been stripped via the proxy at some point. But I need the URL to stay intact so the that the Apache rule can route the parameters correctly.
I have looked at other answers with similar titles and none of them solve my problem e.g: keep double slashes when working with passenger
https://stackoverflow.com/questions/4320774/nginx-how-to-keep-double-slashes-in-urls
https://stackoverflow.com/questions/14832780/nginx-merge-slashes-redirect
https://stackoverflow.com/questions/22759345/nginx-trailing-slash-in-proxy-pass-url
https://stackoverflow.com/questions/5834025/how-to-preserve-request-url-with-nginx-proxy-pass
...
If anyone has any suggestions or can point me in the right direction that would be great?
Thanks in advance
0 Answers