我在 /wp 目录下有一个 wordpress 网站,带有 nginx 网络服务器。我想将 /wp/wp-admin 文件限制到我的私人 IP 地址,并向未经授权的客户端返回错误。问题是 wp-admin 文件夹很容易被限制,但文件仍然可以访问!
server {
root /usr/share/nginx/html;
index index.html index.htm index.php;
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /main {
index index.php;
try_files $uri $uri/ /wp/index.php?q=$uri;
}
error_page 500 502 503 504 404 403 400 /error.html;
location = /error.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
答案1
执行此操作的方法是使用location
配置文件中的一个节,例如:
location /wp/wp-admin/ {
allow 192.168.1.0/24;
deny all;
}
您的问题听起来好像您已经尝试过此操作但没有成功?您可以发布此目录的确切配置吗?
答案2
wp-admin
仍需通过 PHP
location ~ ^/(wp-admin|wp-login.php)(/.*) {
error_page 403;
deny all;
allow 1.2.4.5;
add_header X-Admin "admin";
add_header X-Cache $upstream_cache_status;
// 1st way, create create a common fastcgi_pass
include conf-settings/php-live.conf; // most important
// 2nd way, add fast_cgi directly
fastcgi_pass thg_upstream_php;
}