Home >Backend Development >PHP Tutorial >apache前端+nginx后端,nginx如何rewrite正确的地址

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

WBOY
WBOYOriginal
2016-06-06 20:41:371134browse

运行环境
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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn