How to write nginx reverse proxy configuration
滿天的星座
滿天的星座 2017-05-16 17:26:53
0
1
432

The effect I want:

http://hostname/proxy/3000
http://127.0.0.1:3000

http://hostname/proxy/3000/anything
http://127.0.0.1:3000/anything

There is a requirement: the port is changed

I tried

location ~ /proxy/(\d+) {
        proxy_pass http://127.0.0.1:;
        rewrite ^/(.*)$ / break;
    }

But rewrite has problems no matter how it is written

How to write in nginx configuration, wait online~

滿天的星座
滿天的星座

reply all(1)
漂亮男人

proxy_pass 的文档里有讲:location 使用了正则后,proxy_pass The URI part in the parameters following the directive will be ignored. You can use the following configuration to indirectly achieve the function you want:

server {
    listen       80;
    server_name  localhost;

    location /proxy/ {
        rewrite ^/proxy/(\d+)/(.*)  /internal?port=&url= last;
    }

    location /internal {
        internal;
        proxy_pass http://127.0.0.1:$arg_port/$arg_url;
    }
}   
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!