我当前的nginx配置看起来像这样
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name api.myapp.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
将生产Web应用程序托管在api.example.com
上,但是现在我需要另一个配置来进行暂存构建。我可以旋转节点的另一个过程,使暂存webapp可在http://localhost:3002
上访问,但是由于暂存webapp也必须是https,所以第二个配置块应该在nginx中吗?
答案 0 :(得分:0)
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
listen [::]:443 ssl;
server_name api.myapp.com;
###
ssl configure
###
location / {
if ($server_port = 443) {
proxy_pass http://localhost:3002;
}
if ($server_port = 80) {
proxy_pass http://localhost:3001;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}