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


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

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM