[英]Nginx try_files won't trigger response from index.php
我有一個問題,try_files似乎無法將對不存在文件的請求傳遞到最后指定的值(在我的情況下為index.php)。 我使用的是Wordpress和XML Sitemaps生成器插件,用於創建虛擬XML文件和由Wordpress處理的虛擬robots.txt。 不幸的是try_files似乎沒有將對這些文件的請求傳遞給Wordpress。
這是我的服務器配置:
server {
## Web domain
server_name christiaanconover.com;
## Site root
root /var/www/christiaanconover.com;
## Index
index index.php index.htm;
## Common Wordpress configuration
include wp.conf;
## Include PHP configuration
include php.conf;
## Gzip Compression
include gzip.conf;
## Include W3TC configuration
include /var/www/w3tc/christiaanconover.com;
}
我在此服務器上運行多個單獨的Wordpress站點,因此為了節省時間,我創建了一個文件wp.conf,其中包含Wordpress的所有常用配置元素。 這是wp.conf的內容:
location / {
## Prevent PHP files from being served as static assets, and fall back to index.php if file does not exist
try_files $uri $uri/ /index.php?$args;
## If a file exists, serve it directly
if (-f $request_filename) {
break;
}
## Wordpress Rewrite
if (!-e $request_filename) {
rewrite ^ /index.php last;
}
}
其他所有功能均正常運行,但try_files安排似乎無法正常執行。 有任何想法嗎?
您遇到了http://wiki.nginx.org/IfIsEvil#Examples中描述的問題之一
ifs
您在wp.conf
中指定的ifs
wp.conf
則已經用try_files
覆蓋了它們,因此您只需刪除它們即可,結果是:
location / {try_files $uri $uri/ /index.php$is_args$args;}
那將:
/index.php$is_args$args
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.