nginx appears to use rewrite regardless of server_name -
i have following config file.
server { listen 80; server_name web.example.com; access_log /var/www/example/shared/log/web.access.log; error_log /var/www/example/shared/log/web.error.log debug; rewrite ^/(.*)$ http://www.example.net$request_uri; permanent; }
when make request curl -ii -h "host: example.com" http://example.com above rewrite rule works. (argh)..
the server_name explicitly says "web.example.com"
2014/11/18 22:49:20 [notice] 30694#0: 1868 "^/(.)$" matches "/", client: 1.2.3.4, server: web.example.com, request: "head / http/1.1", host: "example.com" 2014/11/18 22:49:20 [notice] 30694#0: *1868 rewritten redirect: "http://www.example.net/", client: 1.2.3.4, server: web.example.com, request: "head / http/1.1", host: "example.com"
not present here other server { } configs. xavier (below) pointed out had set default_server listen: 443; not listen: 80. (argh)
that's not strict solution issue.
what's happening have 1 server block , becomes default server block requests, ones not matching server name. need add default server block in configuration :
server { listen 80 default_server; }
by way, have typo (semicolon before permanent
) , don't need rewrite have specific regular expression. use instead :
return 301 http://www.example.net$request_uri;
Comments
Post a Comment