一、需求
- 就是根据传入的域名,访问不同的应用,域名后是不带端口的(都要使用默认的80端口)
blog.test.com
访问 nginx 时跳转到 blog项目 的端口 8081
gogs.test.com
访问 nginx 时跳转到 gogs项目 的端口 8082
二、配置
server{
listen 80;
server_name blog.test.com;
location / {
proxy_pass http://localhost:8081;
proxy_http_version 1.1;
……
}
}
server{
listen 80;
server_name gogs.test.com;
location / {
proxy_pass http://localhost:8082;
proxy_http_version 1.1;
……
}
}
三、proxy_http_version 说明
- nginx在代理是默认http版本为1.0,由于文件的下载涉及到使用分块传递,但http1.0是不支持这个特性的。所以服务端为1.0版本无法进行转发。
- 只要在nginx配置的location模块里面加上proxy_http_version 1.1就可以了