1.大家有過這方面的困擾,就是自己的網站給其他人惡意域名解析到自己的服務器ip上。
特別不爽,那大家可以用用空主機頭的方法。
先給大家看下我的nginx.conf配置
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 7070; #端口號
server_name www.syscal.xyz;#指定的域名
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# 禁止其他域名和ip訪問
# 這個default_server 得放在這里,如果放在上面的情況 就會報錯了
#return 500 就是返回了500報錯信息,也可以變成403
server {
listen 7070 default_server;
server_name _;
return 500;
}
}
本地測試已通過