即使在https

时间:2019-09-28 23:28:34

标签: node.js nginx

在数字海洋飞沫上,我使用Docker来容器化我的node.js express(Sails.js)应用程序。我使用docker-compose在小滴上运行它。我按照本教程设置了https:

https://medium.com/@pentacent/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71

现在我有https,但是req.securefalse。 (这会导致Cookie无法投放的问题,但这无关紧要-我的目标是将req.secure设置为true)。

我在快速会话中添加了一些日志记录-在https://github.com/expressjs/session/blob/master/index.js#L625之上-发现req.secure记录为假时。有人对如何实现它有任何想法吗?

这是我的Nginx配置:

server {
    listen 80;
    server_name REMOVED_MY_SITE.net;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name REMOVED_MY_SITE.net;

    ssl_certificate /etc/letsencrypt/live/REMOVED_MY_SITE.net/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/REMOVED_MY_SITE.net/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://localhost:1337;
        proxy_redirect     off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    }
}

0 个答案:

没有答案