使用letsencrypt启用https后,django无法正常工作

时间:2019-06-24 08:56:37

标签: django nginx gunicorn django-supervisor

我的网站在没有https(例如https)domain:8001的情况下运行良好,但是当我尝试访问域名:8001时添加了letencrypt证书后,它会按照ngnix中的代码自动转到https重定向,但是服务器没有响应。

我已经在http中尝试过了,但效果很好。但是在https letsencrypt证书中,服务器没有响应

    Gunicorn.conf.py

proc_name = 'myapp'
bind = 'ip:8001'
workers = 4
timeout = 1800
graceful_timeout=1800
user = 'root'
group = 'www-data'
loglevel = 'debug'
errorlog = '/home/logs/gunicorn.error.log'
accesslog = '/home/logs/gunicorn.access.log'


Nignx Configuration:

server {
    server_name domainname.com www.domainname.com;

location / {
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
  }

    location /api/ {
        proxy_pass http://127.0.0.1:8001; 
        proxy_set_header Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/nuvays.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nuvays.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.domainname.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = domainname.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name domainname.com www.domainname.com;
    return 404; # managed by Certbot




}


Supervisor:

[program:app]
environment=LANG="en_US.utf8", LC_ALL="en_US.UTF-8", LC_LANG="en_US.UTF-8"
command = /usr/local/bin/bin/gunicorn app.app:application -c /home/conf/gunicorn.conf.py
directory =/home/app
user = root
loglevel = debug
stdout_logfile = /home/logs/supervisor.log
stderr_logfile = /home/logs/supervisor.error.log
autostart = true
autorestart = true
redirect_stderr = true

0 个答案:

没有答案