如何使用HTTPS

时间:2015-04-24 14:24:36

标签: django ssl nginx https uwsgi

我正在尝试设置uWSGI + Nginx with HTTPS

以前的版本适用于HTTP,但现在它无法使用HTTPS。

该网站正在使用Django 1.7 and Python 2.7

以下是配置文件。谁能发现需要改变的东西?

uwsgi.ini

[uwsgi]
# %d is the dir this configuration file is in
socket = my.i.p.addr:9000 
chmod-socket = 666
master = True
processes = 4

# chdir to the folder of this config file, plus app/website
chdir = %dmysite/
module = mysite.wsgi:application

# create a pidfile
pidfile = /tmp/mysite-master.pid 
harakiri = 10 # respawn processes taking more than 20 seconds
max-requests = 5000 # respawn processes after serving 5000 requests

# will be run via `supervisord` so don't need to daemonize
#daemonize = /var/log/uwsgi/mysite.log

mysite.conf [对于Nginx]:

upstream uwsgicluster {
    server my.i.p.addr:9000 fail_timeout=0;     
}
server {
        listen       80;
        server_name  mysite.com;
        rewrite ^ https://$http_host$request_uri? permanent;    # force redirect http to https
    }
server {
    listen          443;
    server_name     mysite.com;
    charset         utf-8;

    root            /opt/django/mysite/mysite;
    access_log      /var/log/nginx/access_ssl.log combined;
    error_log       /var/log/nginx/error_ssl.log error;

    client_max_body_size 4G;
    keepalive_timeout 5;

    #SSL Settings
    ssl on;
    ssl_certificate /etc/nginx/ssl/mysite.com.crt;
    ssl_certificate_key /etc/nginx/ssl/mysite.com.key;

    location /static/ {
        autoindex on;
        alias /opt/django/mysite/static/; 
    }

    location / {
        # uWSGI config
        include uwsgi_params;
        proxy_pass http://uwsgicluster;
        uwsgi_read_timeout 300;
        uwsgi_param UWSGI_SCHEME $scheme;

        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   X-Forwarded-Host $server_name;
    }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /opt/django/mysite/templates/error;
    }
}

其他信息:

客户提供此回复:The webpage is not available: ERR_CONNECTION_RESET

对于Nginx日志,我的/var/log/nginx/error.log并未显示任何错误。

我认为我没有正确设置uwsgi.log,因为我无法找到它,或者看不到任何内容:/var/log/uwsgi/...

我会在日志中查看该页面的响应代码吗?

此外,upstream server IPNginx IP是否需要不同?

如果是这样,当uWSGI不是HTTPS时,是否会进入无限循环以重定向到HTTPS端口?

0 个答案:

没有答案