nginx 如何禁止指定ip访问【附代码】

今天爱分享给大家带来nginx 如何禁止ip访问【附代码】,希望能够帮助到大家。

编辑nginx.conf文件,编辑server前如下所示

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

server_name localhost;修改为server_name _;即可禁止IP访问

Nginx

配置代理转发 报nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf的解决办法

2020-10-22 18:26:41

Nginx

no “events” section in configuration nginx启动报错【解决办法】

2020-11-20 13:36:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧