首页 >后端开发 >php教程 >apache前端+nginx后端,nginx如何rewrite正确的地址

apache前端+nginx后端,nginx如何rewrite正确的地址

WBOY
WBOY原创
2016-06-06 20:41:371133浏览

运行环境
centos 6.5 + lanmp
apache作后端,nginx作前端
软件: wordpress

nginx虚拟主机配置如下:
server {
listen 80;
server_name xxx.com;
root /var/www/xxx/html;
index index.html index.htm index.php;

<code>#这句是wordpress的rewriter语句
location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

#php文件转发给apache处理
location ~ \.(php)?$ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8080;
}
</code>

}

如果是在lnmp环境下,下面的rewrite语句是没问题的
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

但在lanmp环境下,点击地址后,地址栏的地址是变了,显示的页面却是首页。不知道是哪里错了?

固定链接样式:http://xxx.com/xxx/

回复内容:

运行环境
centos 6.5 + lanmp
apache作后端,nginx作前端
软件: wordpress

nginx虚拟主机配置如下:
server {
listen 80;
server_name xxx.com;
root /var/www/xxx/html;
index index.html index.htm index.php;

<code>#这句是wordpress的rewriter语句
location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
}

#php文件转发给apache处理
location ~ \.(php)?$ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://127.0.0.1:8080;
}
</code>

}

如果是在lnmp环境下,下面的rewrite语句是没问题的
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

但在lanmp环境下,点击地址后,地址栏的地址是变了,显示的页面却是首页。不知道是哪里错了?

固定链接样式:http://xxx.com/xxx/

<code>location / {
    try_files $uri @apache ;
}

location @apache {
    internal;
    proxy_pass http://127.0.0.1:8080;
}
</code>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn