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