nginx can be tricky sometimes:
I want to
- redirect all incoming requests for
www.sub.domain.com/*
towww.other.domain.com/*
- use a proxy so users still see the original
www.sub.domain.com
when browsing the site - add an exception for specific URLs (all the same kind):
www.sub.domain.com/script
needs to redirect towww.yet.another.domain.com/www.sub.domain.com/new_script
, preserving the entered POST data for the script. With the little trickiness that the folder containingnew_script
is named just after the original domain.
Here's what I got so far:
server {
listen xx.xx.xx.xx:80;
root /var/www;
index index.html index.htm;
server_name www.sub.domain.com;
location /cms/ {
proxy_pass http://yy.yy.yy.yy:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location /script {
proxy_pass http://www.yet.another.domain.com/www.sub.domain.com/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location / {
proxy_pass http://yy.yy.yy.yy:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite ^/int/a.([a-zA-Z]+).([0-9]+)$ /site/int/a?l=$1&i=$2 last;
rewrite ^(.*)$ /site/$1 last;
}
}
On accessing www.sub.domain.com/script
, this happens:
curl -I www.sub.domain.com/script
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.0
Date: Mon, 04 Aug 2014 04:12:23 GMT
Content-Type: text/html
Content-Length: 184
Location: http://www.sub.domain.com/script/
Connection: keep-alive
In addition, a 404 error is shown: "Not Found: The requested URL /www.sub.domain.com/ was not found on this server."
Where's my mistake? I can't spot it. (Or is it a bunch of mistakes? I'm quite new to nginx redirects.)
Thanks a lot!
location
should belocation /script
, notlocation /new_script
.