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