问题原文
原帖链接 · simonlehmann · CC BY-SA 3.0
I have a website running on an Nginx web server which runs over HTTPS. I noticed recently that someone has pointed their domain to my web server and Nginx is serving my website to this bad domain. It looks like it's even indexing in google...
Nginx config:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.com/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;
root /var/www/example.com;
index index.html;
}
I have tried adding an if statement to check if the $host matches the server_name as recommended here
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.com/ssl-bundle.crt;
ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key;
# Check if incoming hostname matches server_name
if ($host != $server_name) {
# If not, return 404
return 404;
}
root /var/www/example.com;
index index.html;
}
This addition didn't seem to help. Is any of this on the right track? Any suggestions would be much appreciated
已采纳解答
原帖链接 · Pothi Kalimuthu · CC BY-SA 3.0
I have a website running on an Nginx web server which runs over HTTPS. I noticed recently that someone has pointed their domain to my web server and Nginx is serving my website to this bad domain. It looks like it's even indexing in google...
The best way to deal with this or a similar situation is to create a default catchall server block. For example, here's what I have to serve other domains that are pointed towards my server's IP.
server {
listen 80 default_server;
server_name _;
# deny all
location / {
return 403;
}
}
I hope that helps!
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
