Nginx子域,重定向太多

Nginx子域,重定向太多,nginx,digital-ocean,Nginx,Digital Ocean,我有一个带有letsEncrypt SSL的nginx配置,用于以下方面 mysite.com api.mysite.com 虽然mysite.com工作正常,但api.mysite.com返回的重定向错误太多 app.mysite.conf server { root /home/product/; location / { proxy_pass http://127.0.0.1:3000; proxy_http_ve

我有一个带有letsEncrypt SSL的nginx配置,用于以下方面

mysite.com api.mysite.com

虽然mysite.com工作正常,但api.mysite.com返回的重定向错误太多

app.mysite.conf

server {
        root /home/product/;
        location / {
           proxy_pass http://127.0.0.1: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;
        }

    listen [::]:80;
    server_name api.mysite.com www.api.mysite.com
    index index.html index.htm;
    return 301 https://$host$request_uri;
}

server {
    # the condition below results in too many redirects error
    if ($host = api.mysite.com) {
     return 301 https://$host$request_uri;
    }
    listen 443 ssl;
    root /home/app-back-end/;
    index index.html index.htm;
    server_name api.mysite.com www.api.mysite.com;

    # ssl configuration;
    ssl_certificate /etc/letsencrypt/live/api.mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.mysite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
经过长时间的尝试,我意识到在我注释了SSL块内下面的行之后,错误停止了

if ($host = api.mysite.com) {
     return 301 https://$host$request_uri;
 }

然而,现在I api.mysite.com返回403禁止。而api.mysite.conf包含在主nginx.conf中。主要的mysite.com运行良好。但是子域有这个错误。请问我错过了什么?任何帮助都将不胜感激。

您所展示的配置完全不清楚。
www.api.mysite.com
域名的用途是什么?哪些是
root/home/product/
root/home/app后端/目录?如果您的api是node.js websockets后端应用程序,为什么在这里使用它们?为什么一个服务器块只在IPv6上侦听,而另一个只在IPv4上侦听?在
/etc/letsencrypt/live/api.mysite.com/fullchain.pem
证书的SAN(主题备选名称)字段下实际列出了哪些域?这一切都是一个机器人干的吗?