常规配置1图解
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.3.3:8080;
proxy_redirect off;
}
}
http://www.boke.com后,将显示http://192.168.3.3:8080的web信息 代理成功
通过curl查看结果得出
[root@localhost nginx]# curl -I http://www.boke.com/web
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 24 Dec 2015 12:02:00 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: http://192.168.3.3:8080/web/
这里location为带有后端服务器实际地址跟端口的响应头信息这样在实际线上是不允许的所以这里我们打算通过proxy_redirect将被代理服务器的响应头中的location字段进行修改后返回给客户端
配置2
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.3.3:8080;
proxy_redirect http://192.168.3.3:8080/web/ http://www.boke.com/web/;
}
server {
listen 80;
server_name www.boke.com;
location / {
proxy_pass http://192.168.3.3:8080;
proxy_redirect ~^http://192.168.3.3:8080(.*) http://www.boke.com$1;
}
curl查看返回结果
[root@localhost nginx]# curl -I http://www.boke.com/web
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 24 Dec 2015 12:08:34 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: http://www.boke.com/web/
代理后端的服务器信息将不再显示,取而代之的是只显示访问代理本身