我有以下运行良好的nginx配置:
#wordpress
location /wordpress/ {
index index.php;
alias /usr/share/webapps/wordpress/;
try_files $uri $uri/ wordpress/index.php?$args;
}
location ~ \.php$ {
alias /usr/share/webapps/;
include fastcgi.conf;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location "^/wordpress/.*\.(js|css|png|jpg|jpeg|gif|ico)$" {
expires max;
}
并且我正在尝试将网址位置更改为“ hidden_wordpress”,因此我尝试了以下操作:
#wordpress
location /hidden_wordpress/ {
index index.php;
alias /usr/share/webapps/wordpress/;
try_files $uri $uri/ wordpress/index.php?$args;
}
location ~ \.php$ {
alias /usr/share/webapps/;
include fastcgi.conf;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location "^/hidden_wordpress/.*\.(js|css|png|jpg|jpeg|gif|ico)$" {
expires max;
}
但是在这种配置下,我会不断收到这些错误日志:
==> nginx_error.log <==
2018/12/18 20:35:38 [error] 30923#30923: *1 FastCGI sent in stderr: "Unable to open primary script: /usr/share/webapps//hidden_wordpress/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /hidden_wordpress/ HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: ""
我没有将wordpress内容移到“ hidden_wordpress”文件夹,因为我不想更改它。
似乎php部分的网址未正确重写。关于如何实现这一目标的任何想法?
答案 0 :(得分:1)
您的SelectedValue
块无法正确解析以location ~ \.php$
开头的URI。
使用嵌套的位置块,以便可以继承/hidden_wordpress
指令的效果。
例如:
alias
使用location ^~ /hidden_wordpress {
index index.php;
alias /usr/share/webapps/wordpress;
if (!-e $request_filename) { rewrite ^ /hidden_wordpress/index.php last; }
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
...
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass php;
}
location ~ \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
}
}
获取别名文件的正确路径。由于this issue,请避免将$request_filename
与try_files
一起使用。关于alias
的使用,请参见this caution。