Django部署https + gunicorn和nginx

时间:2015-03-29 07:09:03

标签: python django ssl nginx gunicorn

我很难在带有nginx和gunicorn的aws上使用django设置https。

我的配置是:

server {
  listen  80;

  listen 443 ssl;
  server_name logitech.enterpriselist.com;
  rewrite ^ https://logitech.enterpriselist.com$request_uri? permanent;
  root /home/ubuntu/git/elist/static/; 
  #`   ssl on;
  ssl_certificate /etc/ssl/elist.crt; 
  ssl_certificate_key /etc/ssl/elist.key;
  location / {
         #    proxy_pass http://logitech.enterpriselist.com/;
  }
  location /static/ {
      alias /home/ubuntu/git/elist/static/;

  }
}

使用端口8001的http工作正常:

 gunicorn configs.wsgi:application --bind 172.31.14.102:8001`

而不是域名 http://logitech.enterpriselist.com:8001/

但是我也想用默认端口运行这些东西,但是当我运行

gunicorn configs.wsgi:application --bind 172.31.14.102:80

它说地址已经在使用!

当我打开http://logitech.enterpriselist.com/时使用https,它会转到https://logitech.enterpriselist.com/,但它说网站有重定向循环,所以我需要帮助来排序。

1 个答案:

答案 0 :(得分:1)

你还没有告诉nginx它应该代理对gunicorn的请求。特别是,您需要proxy_pass指令和upstream部分。

另外,你不想在端口80上运行gunicorn,因为那是nginx已经绑定的内容。这就是代理的用途。

gunicorn deployment docs有一个示例nginx配置,可以正常工作。