繁体   English   中英

使用uwsgi和Nginx在Django 1.7+中设置Https

[英]Setting up Https in Django 1.7+ with uwsgi and Nginx

我在使用https设置网站时遇到问题。 目前,我已将我的nginx服务器设置为侦听http和https响应。

但是,现在我只想允许https并将任何http请求重定向到htpps。

我没有运气就尝试了这篇文章: 如何使用Django / nginx部署仅HTTPS站点?

在Django 1.7+中推荐这样做的推荐方式是什么?

以下是我的ngninx.conf文件:

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///uwsgi-tutorial/mysite/mysite.sock; # for a file socket
#   server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen 80;
    listen 443 default_server ssl;
    #ssl on;
    ssl_certificate     /uwsgi-tutorial/conf/www.example.com.chained.crt;
    ssl_certificate_key /uwsgi-tutorial/conf/www.example.com.key;

    # the domain name it will serve for
#   server_name localhost; # substitute your machine's IP address or FQDN
    server_name example.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /uwsgi-tutorial/mysite/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /uwsgi-tutorial/mysite/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /uwsgi-tutorial/mysite/uwsgi_params; # the uwsgi_params file you installed
    }
}

已经有一个图书馆可以很好地完成这项工作-sslify:

https://github.com/rdegges/django-sslify

只需按照github页面上的说明进行即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM