Reputation: 433
i have just freshly installed nginx and created a new configuration for test.example.com. Which works.
But also example.org points to my server. Now if I go to example.org nginx redirects me to test.example.com.
I've read that you need to create a default server entry and e.g. return 444; Which is what I did. This is my configuration for the site:
server {
listen IP:80;
server_name test.example.com;
server_tokens off;
root /nowhere;
rewrite ^ https://test.example.com$request_uri permanent;
}
server {
listen IP:443;
server_name test.example.com;
server_tokens off;
root [...];
[...]
}
The default server entry I added in the nginx.conf before (also tried after) "include /etc/nginx/sites-enabled/*;"
server {
# use default instead for nginx 0.7.x, default_server for 0.8.x+
listen IP:80 default_server;
server_name _;
return 444;
}
For me this looks correct. But I still get redirected from example.org to test.example.com.
Upvotes: 3
Views: 7290
Reputation: 25701
You shouldn't have a server_name set at all in the default one. It does need to be before your actual server block in the nginx config.
Also 444 is a weird error to return. You should just return a 404 to indicate that the server is not found, rather than the custom Nginx error code.
Edit
As for the SSL not working, you don't appear to have actually set the SSL certificates in your config file or turned ssl on.
server {
listen 443 default_server ssl;
ssl_certificate /usr/local/nginx/conf/cert.pem;
ssl_certificate_key /usr/local/nginx/conf/cert.key;
server_name test.example.com;
server_tokens off;
root [...];
}
Upvotes: 1