nginx - proxy rule conflict?
ringa_lee
ringa_lee 2017-05-16 17:26:41
0
1
1032
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;
 }

The above proxy rules will not take effect. If you delete the rewrite rules, it will be fine. Is there a conflict? How to modify it?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
小葫芦

rewrite 优先级较高,导致路径已经先被重写了。可以都改用locationGo and match.

    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;
    }  

But are you sure that static files also need to be rewritten to index.php?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!