我有两个问题,但我认为它们是相关的。子目录(如/wp-admin
,/blog
返回404),因此永久链接在跟随时不起作用/blog/category1/page.php
我的设置:
我有一台192.168.1.4
运行nginx的服务器。在另一台服务器上,192.168.1.1
我有一台使用virtualhosts的apache Web服务器,该服务器托管了我的wordpress网站。在没有nginx的情况下,安装程序可以正常运行,但是当我打开nginx时,出现了一些问题。
Nginx不适用于永久链接。我已经使用了default,所以现在使用like: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`
你有一些有效的配置。nginx
在你的配置中,其目的是向Apache服务器反向代理。该index
和try_files
在这种情况下,不恰当的。尝试:
server {
server_name mywebsite.co.uk www.mywebsite.co.uk;
location / {
proxy_pass http://192.168.1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
我敢肯定,我尝试过了,但是它确实可以正常工作……非常感谢!