我尝试了很多不同的东西。我现在的重点是:
location ^~ /wordpress {
alias /var/www/example.com/wordpress;
index index.php index.html index.htm;
try_files $uri $uri/ /wordpress/index.php;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(/wordpress)(/.*)$;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/wordpress/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
现在,据我所知,所有资源(图像等)都在正确加载。并且 http://www.example.com/wordpress
加载了 wordpress,但是页面显示“找不到页面”。 (虽然 WordPress 正在用于此目的)。如果我尝试任何帖子网址,我都会得到相同的结果,“找不到页面”。所以我知道问题是 wordpress 没有获取有关路径或其他内容的数据。另一个潜在的问题是,如果我运行 example.com/wp-admin.php
那么它仍然会运行 index.php
。
需要传递什么数据?这里可能出了什么问题?
最佳答案
由于您的位置别名结束匹配,您应该只使用 root。此外,不是 everything 是通过 wordpress afaik 上的 index.php 路由的。此外,除非您知道您需要路径信息,否则您可能不需要。我想你想要这样的东西:
location @wp {
rewrite ^/wordpress(.*) /wordpress/index.php?q=$1;
}
location ^~ /wordpress {
root /var/www/example.com;
index index.php index.html index.htm;
try_files $uri $uri/ @wp;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
或者如果您确实需要路径信息(网址看起来像/wordpress/index.php/foo/bar):
location ^~ /wordpress {
root /var/www/example.com;
index index.php index.html index.htm;
try_files $uri $uri/ /wordpress/index.php;
location ~ \.php {
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
}
编辑:更新第一台服务器{}以从 uri 中去除初始/wordpress 并将余数作为 q 参数传递
EDIT2:命名位置仅在服务器级别有效
关于php - Nginx - wordpress 在子目录下,应该传递什么数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6154879/