Cloudflare Nginx HTTPS代理传递每个路径

cfh9epnr  于 2023-01-16  发布在  Nginx
关注(0)|答案(1)|浏览(209)

我尝试用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毫秒内得到响应。

x7yiwoj4

x7yiwoj41#

1.更改nginx配置(如果您已经启用了“always 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.设置云耀斑设置:

1.启用始终使用https:

相关问题