【发布时间】:2021-10-03 04:00:57
【问题描述】:
我正在尝试将我的 nginx 配置为支持不同端口的 ssl。如果我为运行我的反应应用程序的端口 3000 执行此操作,那么只有它变为 https,这意味着它不允许端口 5000 请求通过,因为 5000 仍然是 http。我正在使用aws ec2。下面是我的 nginx 默认文件的代码。
enter code here
server {
listen 80;
listen [::]:80;
server_name merkle.org www.merkle.org;
return 301 https://merkle.org$request_uri;
}
server {
listen 443 ssl;
server_name merkle.org web.merkle.org;
# Certificate
ssl_certificate /etc/nginx/ssl/merkle_org.crt;
# Private Key
ssl_certificate_key /etc/nginx/ssl/private.key;
location / {
# My react
proxy_pass http://localhost:3000;
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;
}
location /5000{
# This is my nodejs API
proxy_pass http://localhost:5000;
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;
}
}
【问题讨论】:
-
location /5000块会导致传入请求https://merkle.org/5000被路由到http://localhost:5000/5000,这可能不是您想要的。我猜location /api会是一个合理的选择。