[英]Wordpress and NGINX /wp-admin redirect loop
My nginx.conf
has a server blog containing this: 我的
nginx.conf
有一个包含以下内容的服务器博客:
location ~ \.php$ {
root /var/www/html/blog;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location /blog {
root /var/www/html/blog;
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
But with these settings when I try to access /blog/wp-admin
my browser gets stuck in some redirect loop. 但是使用这些设置,当我尝试访问
/blog/wp-admin
我的浏览器陷入了某些重定向循环。
If I change the root URLs in nginx.conf
to /var/www/html
, /blog/wp-admin
works, but my post permalinks give me a 404 error. 如果我将
nginx.conf
的根URL更改为/var/www/html
,则/blog/wp-admin
可以工作,但是我的帖子永久链接给我一个404错误。
My WP files are located in /var/www/html/blog
. 我的WP文件位于
/var/www/html/blog
。 I have 'SSL Insecure Content Fixer' plugin installed because my images giving a mixed content error on my site, which has a Cloudflare page rule to always use SSL. 我安装了“ SSL不安全内容修复程序”插件,因为我的图像在我的网站上出现了混合内容错误,该错误具有始终使用SSL的Cloudflare页面规则。
My WP address
and WP home
are both set to http://xxx/blog
. 我的
WP address
和WP home
都设置为http://xxx/blog
。
Anybody fixed something similar? 有人修理过类似的东西吗?
Thanks 谢谢
I think that the main problem is an inconsistency with your root
directive. 我认为主要问题是与您的
root
指令不一致。 Your PHP configuration has WordPress in /var/www/html/blog
whereas your static configuration has WordPress in /var/www/html/blog/blog
. 您的PHP配置在
/var/www/html/blog
具有WordPress,而您的静态配置在/var/www/html/blog/blog
具有WordPress。
Assuming that WordPress is installed in the root of /var/www/html/blog
and that the URIs should be prefixed with /blog/
for both real files and permalinks, the correct URI for the entry point should be /blog/index.php
. 假设WordPress安装在
/var/www/html/blog
的根目录中,并且对于真实文件和永久链接,URI均应以/blog/
作为前缀,那么入口点的正确URI应为/blog/index.php
。
The nginx.conf
file should probably be: nginx.conf
文件可能应该是:
root /var/www/html;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
location /blog {
include /etc/nginx/mime.types;
try_files $uri $uri/ /blog/index.php;
}
If you have a conflicting root
directive within the outer server
container, the above root
directive could be placed inside the two location
blocks unmodified . 如果外部
server
容器中的root
指令有冲突,则可以将以上root
指令放置在未经修改的两个location
块内。
I would try /blog/index.php
rather than /blog/index.php?q=$uri&$args
as the last element of try_files
because in my experience, WordPress uses the REQUEST_URI parameter to route permalinks rather than the q
argument as you have implied, but YMMV. 我会尝试使用
/blog/index.php
而不是/blog/index.php?q=$uri&$args
作为try_files
的最后一个元素,因为根据我的经验,WordPress会使用REQUEST_URI参数来路由永久链接而不是像q
参数那样路由暗示,但YMMV。
If you do have other applications in this servers root and would like to segregate the WordPress root
more completely, you might nest the PHP location block like this: 如果在此服务器根目录中确实有其他应用程序,并且想更完全地隔离WordPress
root
,则可以这样嵌套PHP位置块:
location ^~ /blog {
root /var/www/html;
include /etc/nginx/mime.types;
try_files $uri $uri/ /blog/index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.