簡體   English   中英

如何在nginx docker elastic beanstalk中將http重定向到https

[英]how to redirect http to https in nginx docker elastic beanstalk

我在使用 nginx 的 docker elastic beanstalk 中托管了 django 應用程序。 對於 SSL,我使用的是 aws 證書。 要將 http 重定向到 https,我嘗試在 docker 容器內使用 nginx 嘗試“x_forwarded_proto”,但出現 502 錯誤。 這是 nginx 配置:

server {

listen      80 default_server;

server_name www.example.com; 

access_log /home/docker/logs/nginx-access.log;
error_log /home/docker/logs/nginx-error.log;


if ($host !~* ^(www.example.com|example.com)$ ) {
    return 444;
}

if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://$host$request_uri;
}

location / {
    uwsgi_pass unix:/var/sockets/api.sock;
    include    /home/docker/server/uwsgi_params; #
  }  
}

任何人都可以為它提出更好的解決方案。

找到了解決方案,只需添加

if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://$host$request_uri;
}

到 eb 實例的 nginx 配置。

這確實是一個 nginx 問題(添加適當的標簽)。

你的配置看起來很復雜。 而是從這個開始。 這是我用來將 http 端口 80 流量重定向到 TLS/SSL 端口 443 流量的方法。

access_log /home/docker/logs/nginx-access.log;
error_log /home/docker/logs/nginx-error.log;

server {
    listen 80;
    server_name www.example.com;

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

server {
    listen      443 ssl;
    server_name www.example.com;

    location / {
        root   /usr/share/nginx/html;
        index  index.html;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM