首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

Windows Nginx 反向代理:兩個域名分別轉發到不同 Tomcat 端口

     編輯:程式設計疑難解答

nginx.conf 正確配置

worker_processes 1;
events { worker_connections 1024; }
http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    upstream tomcat1 { server 127.0.0.1:8080; }
    upstream tomcat2 { server 127.0.0.1:8081; }

    server {
        listen 80;
        server_name www.test.com;
        location / {
            proxy_pass https://tomcat1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }

    server {
        listen 80;
        server_name bbs.test.com;
        location / {
            proxy_pass https://tomcat2;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
        }
    }
}

常見問題

  • server_name 拼寫錯誤(示例中 bbb.test.com vs bbs.test.com)
  • Windows 防火牆阻擋 80 端口
  • Tomcat server.xml 未配置 proxyName/proxyPort 導致重定向錯誤

驗證

nginx -t
nginx -s reload
curl -H "Host: www.test.com" https://localhost/
curl -H "Host: bbs.test.com" https://localhost/
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved