nginx配置指定域名访问,nginx禁止ip访问,配置空主机头 syscal
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; } }
本地测试已通过