nginx - 代理规则冲突?
ringa_lee
ringa_lee 2017-05-16 17:26:41
[Linux讨论组]
location ~ /(test1|test2|test3|test4) {
        proxy_set_header Host "test.com";
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://127.0.0.1;
}

if ($request_filename !~* ^/(.*)\.(zip|js|ico|css|php|xml|txt|html|swf|apk|ipa|plist)$) {
                rewrite ^/(.*)$ /index.php last;
 }

上面proxy规则不会生效,如果删掉rewrite规则就可以,应该是冲突了?改如何修改?

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
高洛峰

rewrite 优先级较高,导致路径已经先被重写了。可以都改用location去匹配。

    location ~ /(test1|test2|test3|test4) {
            proxy_set_header Host "test.com";
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_pass http://127.0.0.1:8080;
    }

    location ~* ^/(.*)\.(zip|js|ico|css|xml|txt|html|swf|apk|ipa|plist)$ {
        rewrite ^/(.*)$ /index.php last;
    }

    location ~ \index.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
    }  

不过确定 静态文件也要重写到 index.php吗?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号