HTTPS 代理设置不会重定向到子目录

HTTPS 代理设置不会重定向到子目录

感谢您的阅读 :-)。我的服务器上有多个应用程序,它们由代理服务器路由。我最近添加了 HTTPS,之后 API 和博客应用程序(分别位于 /api 和 /blog)停止了路由。

我用了Certbot设置 HTTPS 配置。

我还注意到,如果我尝试使用 www. 域通过 HTTP 访问 api/blog,它会起作用。知道为什么会发生这种情况吗?

以下是 Nginx 配置。

server{

    server_name mazinomedia.com;

    location / {
        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;
        proxy_pass http://172.31.14.107:80;
    }

    location /api/ {
        rewrite ^/api/(.*) /$1 break;
        proxy_pass http://172.31.14.107:10010;
    }

    location /blog/ {

        proxy_pass http://172.31.14.107:4000;
    }

    location /forum/ {

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://172.31.14.107:4567;
        proxy_redirect off;

        # Socket.IO Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mazinomedia.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mazinomedia.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server{
    if ($host = mazinomedia.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    if ($host = www.mazinomedia.com) {
        return 301 https://$host$request_uri;
    } # Copied from certbot

    listen 80;

    server_name mazinomedia.com;
    return 404; # managed by Certbot


}

我是服务器配置的新手,花了几天时间在 Google 上搜索,但发现有很多问题,所以提前谢谢大家!^__^

相关内容