【发布时间】:2017-09-26 23:59:37
【问题描述】:
我有两个问题,但我认为它们是相关的。 /wp-admin、/blog 之类的子目录返回 404,因此,永久链接在 /blog/category1/page.php 之后不起作用
我的设置:
我有一台运行 nginx 的服务器 192.168.1.4。在另一台服务器上,192.168.1.1 我有一个使用虚拟主机的 apache 网络服务器,它托管我的 wordpress 网站。没有 nginx 的设置可以正常工作,但是当我打开 nginx 时,我遇到了一些问题。
Nginx 不适用于永久链接。我使用了默认值,所以现在它就像:http://www.mywebsite.co.uk/?page_id=90 可以正常工作(只要它不在子目录中)。
子目录(不是根目录)中的所有内容都会中断。包括管理页面http://www.mywebsite.co.uk/wp-admin,或(在关闭永久链接之前)http://www.mywebsite.co.uk/blog。他们都去404,具体来说:404 Not Found nginx/1.4.6 (Ubuntu)
这是我的配置:
server {
server_name mywebsite.co.uk www.mywebsite.co.uk;
location / {
index index.php;
proxy_pass http://192.168.1.1$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.php?$args; #not working, error: rewrute or internal redirection cycle while interally redirecting to index.php
}
}
作为参考,这是我的永久链接:/blog/%category%/%postname%/
更新
尝试将其添加到我的配置中:
server {
... config above ...
location /wp-admin/ {
index index.php
try_files $uri $uri/ /wp-admin/index.php?$args;
proxy_pass http://192.168.1.1$request_uri;
proxy_set_header Host $host;
}
}
这会在日志中返回一个错误:
rewrite or internal redirection cycle while internally redirecting to "/wp-admin/index.php", client: xxxxx, server: mydomain.co.uk`
【问题讨论】:
-
try_files的第三条路径假定最终移出,但这条路径又回到了这个location。 -
@Deadooshka 是的,你可能是对的。但这是许多帖子建议解决我遇到的问题的方法
-
index还从location进行内部重定向
标签: php wordpress nginx reverse-proxy virtualhost