使用apache2在nginx上进行wordpress的重定向过多 [英] too many redirects for wordpress on nginx with apache2
问题描述
我刚刚在ubuntu 14.04 LTS上安装了wordpress. Nginx充当apache2的反向代理.
I have just installed wordpress on ubuntu 14.04 LTS. Nginx acts as reverse proxy for apache2.
wp-admin工作正常,但无法打开主页.
wp-admin is working fine, but I am unable to open the homepage.
Nginx服务器代码:
Nginx Server Code:
server {
listen 80;
root /var/www/html/testblog;
index index.php index.html index.htm;
server_name testblog.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8182;
}
location ~ /\.ht {
deny all;
}
}
Apache虚拟主机配置:
Apache Virtual Host Conf:
<VirtualHost *:8182>
ServerName testblog.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/testblog
ErrorLog ${APACHE_LOG_DIR}/errortest.log
CustomLog ${APACHE_LOG_DIR}/accesstest.log combined
</VirtualHost>
我的/etc/hosts:
My /etc/hosts:
127.0.0.1 localhost
127.0.0.1 ubuntu
127.0.1.1 testblog.com
我所有的wp文件都在/var/www/html/testblog/文件夹中.
I have all the wp files in the folder /var/www/html/testblog/.
testblog.com/wp-admin:工作正常.
testblog.com/wp-admin: working fine.
testblog.com:重定向过多.
testblog.com: giving too many redirects.
我猜我的设置是正确的.我曾尝试在wp-config.php中定义WP_HOME和WP_SITEURL,但是没有运气.
I guess my settings are correct. I have tried defining WP_HOME and WP_SITEURL in wp-config.php, but no luck.
我的/var/www/html/testblog/.htaccess:
My /var/www/html/testblog/.htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
testblog.com/wp-admin:正常工作.
testblog.com/wp-admin: working.
testblog.com:出现太多重定向错误
testblog.com: giving too many redirects error
我们非常感谢您的帮助.
Any help is highly appreciated.
编辑:我已经禁用了所有插件.
I have already disabled all the plugins.
推荐答案
如果Apache2运行WordPress,则需要配置nginx
来代理所有内容.目前,您同时具有nginx
和Apache2将URI重写为/index.php
的功能,并且由于nginx
首先执行此操作,因此WordPress永远不会看到原始URI.
If Apache2 is running WordPress, you need to configure nginx
to proxy everything. At the moment you have both nginx
and Apache2 rewriting URIs to /index.php
, and because nginx
does it first, WordPress never sees the original URI.
从此开始:
server {
listen 80;
server_name testblog.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8182;
}
}
如果您决定允许nginx
提供某些静态URI,则可以.但是您不能让nginx
将URI映射到/index.php
,因为那是行不通的.
And if you decide to allow some of the static URIs to be served by nginx
fine. But you can't let nginx
map URIs to /index.php
because that will not work.
这篇关于使用apache2在nginx上进行wordpress的重定向过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!