找回密码
 立即注册
CeraNetworksBGVM服务器主机交流IP归属甄别会员请立即修改密码
查看: 26|回复: 3

nginx反向代理的一个问题

[复制链接]

44

主题

56

回帖

412

积分

中级会员

积分
412
发表于 2018-8-17 10:10:55 | 显示全部楼层 |阅读模式
本帖最后由 604542720 于 2018-8-17 10:55 编辑

各位大佬们,我用的是lnmp1.5
反向代理的时候有个问题,如果是纯路径是可以代理过去的,但是如果后面跟了 .php 文件,就代理不过去了,显示404

配置文件如下,http://a.bbbb.com/tt/kk 这种是可以代理到的,但是如果是http://a.bbbb.com/tt/kk.php 就代理不过去了

server
    {
        listen 80;
        #listen [::]:80;
        server_name a.bbbb.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/a.bbbb.com;

        include rewrite/none.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location / {
            proxy_pass http://1.1.1.1;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/a.bbbb.com.log;
    }




-----------------------------------------------------------------------------------------------

搞定了,用这个

For nginx regexp locations have bigger priority than prefix locations. But

If the longest matching prefix location has the “^~” modifier then regular expressions are not checked.

So try to replace


location /rproxy/ {


with


location ^~ /rproxy/ {


Refer: https://stackoverflow.com/questions/29212655/nginx-php-scripts-not-being-called-from-reverse-proxy


我这边这么写就可以了

location ^~ / {
       proxy_pass http://1.1.1.1;
}
回复

使用道具 举报

72

主题

817

回帖

2981

积分

金牌会员

积分
2981
发表于 2018-8-17 10:43:24 | 显示全部楼层
简单点的用宝塔,参考宝塔的配置文件。 反代不是简单的一个 proxy_pass 就完的事情。
回复

使用道具 举报

44

主题

56

回帖

412

积分

中级会员

积分
412
 楼主| 发表于 2018-8-17 10:57:00 | 显示全部楼层
本帖最后由 604542720 于 2018-8-17 10:53 编辑

搞定了,用这个

For nginx regexp locations have bigger priority than prefix locations. But

If the longest matching prefix location has the “^~” modifier then regular expressions are not checked.

So try to replace


location /rproxy/ {


with


location ^~ /rproxy/ {


Refer: https://stackoverflow.com/questions/29212655/nginx-php-scripts-not-being-called-from-reverse-proxy
回复

使用道具 举报

711

主题

1545

回帖

7303

积分

论坛元老

积分
7303
发表于 2018-8-17 10:51:48 | 显示全部楼层
不懂帮顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|HS2V主机综合交流论坛

GMT+8, 2024-5-18 04:44 , Processed in 0.044211 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表