[英]Password protect sub-folder of wordpress website on Nginx server
我正面临一个奇怪的问题。 我已经在 nginx 服务器上为 wp-admin 启用了密码保护但是一旦我启用了密码保护,wp-admin 网页的 php 解析就会停止。
意思是,在我输入用户名和密码后,我可以下载 php 文件源代码,而不是使用登录屏幕查看处理过的 HTML。
这是我的配置文件 请告诉我我做错了什么?
server {
... server stuff here ..
# Wordpress Rules
location / {
try_files $uri $uri/ /index.php?$args;
}
location ^~ /wp-admin/ {
auth_basic "Restricted Access";
auth_basic_user_file /home/user/domains/.htpasswd;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
# Cache control
location ~* \.(jpg|jpeg|png|gif|ico|svg|ttf)$ {
expires 365d;
}
location ~* \.(css|js)$ {
expires 30d;
}
# Enable "Vary-Accept-Encoding" headers
# They are enabled in the nginx.conf
}
如果我删除密码保护,一切正常,管理面板也正常。 我想我没有正确添加密码块。
您可能需要阅读nginx
如何处理请求。
问题是location ^~ /wp-admin/
块无法处理 PHP 文件。
这可能有效,但请尝试使用嵌套块:
location ^~ /wp-admin/ {
auth_basic "Restricted Access";
auth_basic_user_file /home/user/domains/.htpasswd;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.