一、需求
-  就是根据传入的域名,访问不同的应用,域名后是不带端口的(都要使用默认的80端口) 
-  blog.test.com访问 nginx 时跳转到 blog项目 的端口 8081
-  gogs.test.com访问 nginx 时跳转到 gogs项目 的端口 8082
二、配置
- 在 server 中配置即可
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就可以了,完美
四、他山之石
- 求助,如何实现nginx 多域名访问配置不同的应用
- Nginx proxy_http_version默认值引发的问题










