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/