Simple nginx config
server {
listen 0.0.0.0:80;
server_name localhost 127.0.0.1;
location /en-us/ {
return 301 http://www.lego.com;
}
}
Here's what happens when I curl that config without a trailing slash on /en-us.
curl -v http://127.0.0.1/en-us -o /dev/null
# HTTP/1.1 404 Not Found
I expect that 404. The location block is using a prefix match, and so it makes sense to me that /en-us is not matching that block.
Here's where I get confused...
Same config, but with a proxy_pass
Here I use the same config, but instead of returning a 301 I do a proxy_pass.
server {
listen 0.0.0.0:80;
server_name localhost 127.0.0.1;
location /en-us/ {
proxy_pass http://www.lego.com;
}
}
Now watch what happens when I run the same curl.
curl -v http://127.0.0.1/en-us -o /dev/null
# HTTP/1.1 301 Moved Permanently
That 301 on /en-us makes no sense to me. It's redirecting to Location: http://127.0.0.1/en-us/.
In the first config, /en-us seemed to not match my location block (404). In the second config, /en-us did (301).
- Why do the same location rules seem to match differently between my two configs?
- Why would that second config result in a 301 to add a trailing slash?
I'm using nginx version: nginx/1.4.6 (Ubuntu)