如何在http到nginx docker elastic beanstalk中将http重定向到https [英] how to redirect http to https in nginx docker elastic beanstalk

查看:237
本文介绍了如何在http到nginx docker elastic beanstalk中将http重定向到https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的django应用程序托管在docker elastic beanstalk中,它使用nginx。对于SSL,我使用的是aws证书。
要将http重定向到https,我在docker容器中尝试使用了nginxx_forwarded_proto,但是我收到了502错误。这是nginx配置:

I've django application hosted in docker elastic beanstalk, which uses nginx. For SSL i'm using aws certificate. To redirect http to https i tried " x_forwarded_proto " with trhe nginx inside the docker container but i'm getting a 502 error. here's the nginx config:

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

任何人都可以提出更好的解决方案。

Can anyone suggest a better solution for it.

推荐答案

找到一个解决方案,只需添加

Found a solution for it, just add

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

到eb实例的nginx配置。

to the nginx configuration of the eb instance.

这篇关于如何在http到nginx docker elastic beanstalk中将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆