我使用nginx作为apache2的前端。 Apache2将处理所有dynamic内容。
这是我的主要文件,nginx作为apache的前端,并将所有dynamic页面转发到apache2:
server { listen 80; root /var/www/websites/main/htdocs; index index.html index.php index.htm; server_name *removed*; location / { try_files $uri $uri/ /index.php; } 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:81; } location ~ /\.ht { deny all; } }
不幸的是,这会导致redirect循环。
当我使用下面的configuration时,网站加载正常,虽然nginx正在处理所有静态和dynamic内容,这是违背这一点。
server { listen 80; root /var/www/websites/main/htdocs; index index.html index.php index.htm; server_name *removed*; location ~* ^.+\.(ico|jpg|jpeg|gif|png|css|txt|js|flv|swf|html|htm|eot|woff|ttf|svg)$ { access_log off; expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } 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:81; } location ~ /\.ht { deny all; } }
使用Chrome开发人员工具,我发现这是一个301redirect循环。 我可以访问wp-admin没有任何问题。
添加到你的WordPress主题function.php – >
remove_filter('template_redirect', 'redirect_canonical');
我意识到自从你发布你的问题已经有一段时间了,但是如果你还在挣扎中…
我遇到了和你一样的问题,并通过这篇博文解决了这个问题 。 从我可以告诉你需要为你的代理定义一个后端,使用ngx_http_upstream_module( 这里的文档)。 在nginx.conf中,包含以下几行:
http { [...] upstream backend { ip_hash; server 127.0.0.1:8081; #or other IP-address:port config - you may add several } [...] server { [...] location / { try_files $uri $uri/ /index.php; proxy_pass http://backend; } [...] } # END "server" } # END "http"
我认为WordPress的使用某种友好的path风格的URL或redirect,所以你走
index.php -> /nice-url -> index.php -> /nice-url
由于你的try_files – 块。
如果直接访问/index.php会发生什么情况? 你的日志告诉你什么doies?
你应该找一个nginx-worpdress-receipt
试试这个:(Src: http ://wiki.nginx.org/WordPress)
location / { try_files $uri $uri/ /index.php?$args; }
编辑:我也推荐使用PHP通过FastCGI而不是通过Apache。