Django部署https+gunicorn和nginx

2024-04-16 16:44:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在用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一起工作正常:

^{pr2}$

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

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

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

上面写着地址已经被使用了!在

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


Tags: httpsgitcomhttpsslhomeserverubuntu
1条回答
网友
1楼 · 发布于 2024-04-16 16:44:47

你没有什么要告诉nginx它应该是代理请求给gunicorn。尤其需要一个proxy_pass指令和一个upstream部分。在

另外,您不希望在端口80上运行gunicorn,因为nginx已经绑定到这个端口。这就是委托书的目的。在

gunicorn deployment docs有一个nginx配置示例,可以很好地工作。在

相关问题 更多 >