I don't have any rules that suggest https://www.foobar.com
should redirect to https://www.foobar.com
. But why is it doing that?
This is my curl
output:
curl -Ik https://www.foobar.com
HTTP/1.1 301 Moved Permanently
Content-Length: 184
Content-Type: text/html
Date: Wed, 11 Feb 2015 07:22:11 GMT
Location: https://www.foobar.com/
Server: nginx/1.4.7
Connection: keep-alive
Nginx config:
upstream unicorn_www.foobar.com {
server unix:/srv/www/foobar/shared/sockets/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name foobar.com;
return 301 https://www.foobar.com$request_uri;
}
server {
listen 80;
server_name www.foobar.com;
return 301 https://www.foobar.com$request_uri;
}
server {
listen 80;
server_name beta.foobar.com;
return 301 https://www.foobar.com$request_uri;
}
server {
listen 443;
server_name foobar.com;
return 301 https://www.foobar.com$request_uri;
ssl on;
ssl_certificate /etc/nginx/ssl/www.foobar.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.foobar.com.key;
}
server {
listen 443;
server_name beta.foobar.com;
return 301 https://www.foobar.com$request_uri;
ssl on;
ssl_certificate /etc/nginx/ssl/www.foobar.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.foobar.com.key;
}
server {
listen 443;
server_name www.foobar.com foobar_staging pantherinae;
access_log /var/log/nginx/www.foobar.com-ssl.access.log;
ssl on;
ssl_certificate /etc/nginx/ssl/www.foobar.com.crt;
ssl_certificate_key /etc/nginx/ssl/www.foobar.com.key;
keepalive_timeout 5;
root /srv/www/foobar/current/public/;
location / {
try_files $uri/index.html $uri/index.htm @unicorn;
}
location @unicorn {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_read_timeout 60;
proxy_send_timeout 60;
# If you don't find the filename in the static files
# Then request it from the unicorn server
if (!-f $request_filename) {
proxy_pass http://unicorn_www.foobar.com;
break;
}
}
error_page 500 502 503 504 /500.html;
location = /500.html {
root /srv/www/foobar/current/public/;
}
}
It is a redirect to add a trailing slash: from
www.example.com
towww.example.com/
.From the manual
I assume that the proxy_pass to unicorn is what triggers this.
You have a
location /
line in your config. You do a request withcurl -Ik https://www.foobar.com
(Note the missing trailing slash / in your request). Missing slash results in redirect to "correct" URL that matches the location directivehttps://www.example.com/
.