Nginx 反向代理配置proxy_pass

http://blog.csdn.net/h70614959/article/details/37766697

在做验证码测试的时候使用了 PHP 和 Node.js 两种语言,因此需要使用 Nginx 做反向代理。

通过尝试发现 location 可以拦截相关的 URL 代理到对应服务 URL ,配置如下:

location /verification-code-test/nodejs {
    proxy_pass http://127.0.0.1:8082;
}

这样配置后在访问 http://just4fun.chenky.com/verification-code-test/nodejs/touclick 的时候会被代理到 http://127.0.0.1:8082/verification-code-test/nodejs/touclick 而我所期待的地址是 http://127.0.0.1:8082/touclick。

经过搜寻这篇文章给明确的说明:需要在 proxy_pass 的URL地址后面增加 / 以满足上述需求:

location /verification-code-test/nodejs {
    proxy_pass http://127.0.0.1:8082/;
}

这里贴出上面那篇文章中测试的四个例子,访问的地址均为 http://192.168.1.4/proxy/test.html

配置1:

location /proxy/ {
    proxy_pass http://127.0.0.1:81/;
}

会被代理到 http://127.0.0.1:81/test.html 这个url

配置2:

location /proxy/ {
    proxy_pass http://127.0.0.1:81;
}

会被代理到 http://127.0.0.1:81/proxy/test.html 这个url

配置3:

location /proxy/ {
    proxy_pass http://127.0.0.1:81/ftlynx/;
}

会被代理到 http://127.0.0.1:81/ftlynx/test.html 这个url

配置4:

location /proxy/ {
    proxy_pass http://127.0.0.1:81/ftlynx;
}

会被代理到http://127.0.0.1:81/ftlynxtest.html 这个url

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注