Tay*_*sko 5 nginx wordpress php-fpm deny
标题说明了一切,但我有一个非常有趣的问题,我很困惑。基本上,我有一个简单的 WordPress 安装,我希望拒绝一个文件夹(以及文件夹中的所有文件),比如说 /wp-content/themes/default/scripts 但允许某些 IP。
我可以否认这个文件夹的位置,^~/wp-content/themes/default/scripts {deny all;}
就像任何 Nginx 大师都会告诉你的那样。
但是根据我的理解,“^”具有更高的优先级,一旦找到正则表达式匹配项,它将停止搜索其他位置块。因为我不想为每个人拒绝该文件夹(当然,使用allow (IP Address);
,我的^~/wp-content/...
位置块会完全抽出我的 PHP-FPM 位置块以将文件传递给 FastCGI 服务器。当然,当我尝试查看任何文件时在文件夹中,PHP 文件直接下载,因为 PHP 不解析它。
有没有人有想法?我想阻止该文件夹,但要让 PHP 同时为我决定允许的用户工作。这是一个相当棘手的问题。我找不到问题的任何答案。
谢谢你们!真的很感谢你的帮助!
对于任何想知道的人,我当前的 Nginx vhost 配置如下所示:
server {
#..all of the common stuff you would expect
include /folder/nginx.conf; #including some WordPress rewrites for W3 Total Cache
# pass the PHP scripts to FastCGI server listening on UNIX socket
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_read_timeout 1900;
}
location / {
#allowing some IPs...
#deny everyone else
deny all;
#WordPress rewrite for slugs
index index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php last;
}
#rewrite for sitemaps
rewrite ^(.*/)?sitemap.xml /wp-content/sitemap.php last;
}
# denying access to .htaccess files
location ~ /\.ht {
deny all;
}
}
Run Code Online (Sandbox Code Playgroud)
终于找到了答案。当你做这样的事情时,你需要重新声明 PHP-FPM 设置(块中的所有内容)location ~ \.php$ { (this code) }
。
因此,为了避免冗余,我将这些值放入另一个文件中,并留下如下内容:
server {
# pass the PHP scripts to FastCGI server listening on UNIX socket
location ~ \.php$ {
include /etc/nginx/fastcgi_php_text;
}
location / {
index index.php;
}
location ^~/folder/ {
deny all;
allow ...;
include /etc/nginx/fastcgi_php_text;
}
}
Run Code Online (Sandbox Code Playgroud)
不知道这是否是最好的方法,但这是我找到的唯一方法。
归档时间: |
|
查看次数: |
1872 次 |
最近记录: |