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; } }

 

本地測試已通過


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM