1
votes

I am using a block to redirect all http traffic to https. Simple stuff. However, if I address the server directly by IP, it always redirects to the server_name given. If I do not give a server_name, it does not redirect. This is highly undesirable, as I may be on a LAN where a domain name would go unresolved. Here is my redirect block:

server {
    listen   80 default_server; ## listen for ipv4; this line is default and implied
    return 301 https://$server_name$request_uri;
}
1
Use $host or $http_host instead of $server_nameAlexey Ten
Perfect. Y U NO answer?C Reese

1 Answers

2
votes

It redirects to server_name because you set it up like that. Look at your return 301 https://$server_name$request_uri;. Either you replace $server_name by $host or by the IP you want to redirect to.