【问题标题】:Django deployment https + gunicorn and nginxDjango 部署 https + gunicorn 和 nginx
【发布时间】:2015-06-02 07:26:31
【问题描述】:

我坚持使用 django 在 nginx 和 gunicorn 上设置 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

它说地址已经在使用中!

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

【问题讨论】:

  • 你有其他包含 Nginx 或与 Nginx 模拟链接的配置文件
  • 是的,我已经将文件与启用文件夹站点的文件进行了simlinked
  • 我不使用 gunicorn,但在我看来,您要求 nginx 在端口 80 上侦听,但同时您的 gunicorn 也在同一个端口上侦听。您要做的是在 8080 等高端口号上运行 gunicorn,然后让 nginx 在 80 上处理 http 请求,并在您的位置块中为“/”代理到 gunicorn。这有意义吗?

标签: python django ssl nginx gunicorn


【解决方案1】:

你没有任何东西可以告诉 nginx 它应该将请求代理到 gunicorn。特别是,您需要一个 proxy_pass 指令和一个 upstream 部分。

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

gunicorn deployment docs 有一个运行良好的示例 nginx 配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 2013-12-08
    • 1970-01-01
    • 2018-01-28
    • 2014-03-31
    • 2020-04-06
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多