nginx配置只允许某个ip或某些ip进行访问

落爺英雄遲暮 提交于 2019-12-21 16:15:10

在server下配置如下,即成实现只允许某些ip对web的访问了

server
    {
        listen 80;
        #listen [::]:80;
        server_name a.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/a.com;

        if ( $remote_addr !~* "223.184.203.125|223.184.203.131") {#只这些ip访问
            return 403;
        }
  
        include other.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
    }

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!