nginx配置禁止ip访问,只能域名访问

server {
    listen 80; 
    server_name 域名;


#     if ($request_method !~ ^(GET|POST|HEAD)$ ) {
#         return 405;
#     }


    location ~ /.svn/ {
        return 404;
    }


    location ~ ^/(WEB-INF)/ {
        return 404;
    }


#     location ~ \.(apk|torrent|htm|html|asp|php|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|map|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
#         root D:/Servers/ceshiServer/webapps/ROOT;
#         access_log off;
#         expires 30d;
#     }
location / {
root D:/Servers/ceshiServer/webapps/ROOT;
        proxy_pass http://ceshi_server;
        #access_log off;
        include _proxy.conf;
    }
 

}


这是以前的配置文件,可以支持域名访问,ip也能访问,禁止ip访问只需加上一段话


server{ 
listen 80 default; 
server_name _; 
return 404; 
}

完整配置

server{ 
listen 80 default; 
server_name _; 
return 404; 
}

server {
    listen 80; 
    server_name 域名;


#     if ($request_method !~ ^(GET|POST|HEAD)$ ) {
#         return 405;
#     }


    location ~ /.svn/ {
        return 404;
    }


    location ~ ^/(WEB-INF)/ {
        return 404;
    }


#     location ~ \.(apk|torrent|htm|html|asp|php|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|map|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ {
#         root D:/Servers/ceshiServer/webapps/ROOT;
#         access_log off;
#         expires 30d;
#     }
location / {
root D:/Servers/ceshiServer/webapps/ROOT;
        proxy_pass http://ceshi_server;
        #access_log off;
        include _proxy.conf;
    }
 

}

你可能感兴趣的:(nginx)