如何在http nginx dockerpopup的beanstalk中将httpredirect到https

我有一个django应用程序托pipe在docker elastic beanstalk中,它使用nginx。 对于SSL我使​​用aws证书。 将httpredirect到https我试图在docker容器中使用trhe nginx的“x_forwarded_proto”,但是我得到了一个502错误。 这里是nginxconfiguration:

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; # } } 

任何人都可以提出一个更好的解决scheme。

find一个解决scheme,只需添加

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

到eb实例的nginxconfiguration。

这真的是一个nginx问题(添加适当的标签)。

你的configuration似乎很复杂。 从这个开始。 这是我用来redirectHTTP端口80stream量到TLS / SSL端口443stream量。

 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; } }