nginx - 代理規則衝突?
ringa_lee
ringa_lee 2017-05-16 17:26:41
0
1
1006
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嗎?

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!