【问题标题】:Nginx HTTPS proxy_pass every pathNginx HTTPS proxy_pass 每条路径
【发布时间】:2022-02-03 20:25:28
【问题描述】:

我正在尝试使用 nginx 和 cloudflare 设置 https。我使用 cloudflare 生成了一个证书和密钥,并将它们添加到我的 nginx 配置中(见下文)。

server {
    listen 443 ssl;
    server_name <URL_HIDDEN>;

    ssl_certificate /etc/nginx/own-certs/server.crt;
    ssl_certificate_key /etc/nginx/own-certs/server.key;

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

问题:只有主页有效(/)。 当转到 任何 其他页面(如 /favicon.ico)时,我在 30 秒后收到 504 错误。使用特定端口和相同路径 (http://localhost:8082/favicon.ico) 时,一切正常。当我删除 ssl 部分时一切正常。

这不是 nginx 超时问题,因为我在使用 localhost URL 时会在 5 毫秒内得到响应。

【问题讨论】:

    标签: nginx cloudflare


    【解决方案1】:
    1. 更改 nginx 配置(如果您已启用“始终 https”,则也是必需的):
    server {
        listen 80; # ADD THIS
    
        listen 443 ssl;
        server_name <URL_HIDDEN>;
    
        ssl_certificate /etc/nginx/own-certs/server.crt;
        ssl_certificate_key /etc/nginx/own-certs/server.key;
    
        location / {
            proxy_pass http://localhost:8082;
            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;
        }
    }
    
    1. 设置 cloudflare 设置:

    2. 启用始终使用 https:

    【讨论】:

    • 一年多前我已经启用了Always Use HTTPS。但是当我添加 listen: 80; 部分时,一切正常,即使一切都通过 https 而不是 http(我仔细检查了)。
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2017-02-04
    • 2018-02-21
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多