前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >对django网站使用证书

对django网站使用证书

作者头像
超级大猪
发布2019-11-22 09:40:05
5300
发布2019-11-22 09:40:05
举报
文章被收录于专栏:大猪的笔记大猪的笔记

后台用gunicorn启动

gunicorn --bind=0.0.0.0:8000 dazhu.wsgi:application

配置Nginx

参考配置文件如下

代码语言:javascript
复制
upstream  dzapp {
    server 127.0.0.1:8000;
}

server {
    listen      80;
    server_tokens       off;
    # access_log  /var/log/nginx/web2.access.log main;
    server_name 10.67.54.227;
    #server_name www.superpig.win  www.yinzihao.com.cn;
    #if ($host != 'www.superpig.win' ) {
    #rewrite ^/(.*)$ http://www.superpig.win/$1 permanent;
    #}


    location ^~ /admin {
        rewrite ^ https://$server_name:443$request_uri? permanent;
    }

    location /static {
           autoindex on;
           alias /home/yzh/workspace/dazhu/dazhu/static;
    }

    location / {
        proxy_pass http://dzapp;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
    }
}
server {
    listen 443 ssl;
    server_name 10.67.54.227;
    ssl on;
    ssl_certificate /home/yzh/workspace/dazhu/keys/dazhu.cert;
    ssl_certificate_key /home/yzh/workspace/dazhu/keys/dazhu.key;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    ssl_prefer_server_ciphers on;
    location ^~ /admin {
        proxy_pass  http://dzapp;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect     off; 
        ### Most PHP, Python, Rails, Java App can use this header -> https ###
        proxy_set_header X-Forwarded-Proto  $scheme;
    }

    location /static {
           autoindex on;
           alias /home/yzh/workspace/dazhu/dazhu/static;
    }

    location / {
        rewrite  ^  http://$server_name$request_uri? permanent;
    }
}

生成dazhu.cert和dazhu.key

代码语言:javascript
复制
openssl genrsa 1024 > dazhu.key
openssl req -new -x509 -nodes -sha1 -days 365 -key dazhu.key > dazhu.cert

注意填写common name的时候,和Org name的时候填域名,否则出错。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-01-19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 后台用gunicorn启动
  • 配置Nginx
  • 生成dazhu.cert和dazhu.key
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档