ubuntu+uwsgi+nginx+django 部署手记三(配置https)

django rest framwork 为了配合微信小程序的访问,借助nginx ssl 配置https
https 有两部分组成:HTTP + SSL / TLS

#首先,cd 到你想生成证书、私钥的路径下面
#1.创建服务器证书密钥文件 server.key:
openssl genrsa -des3 -out server.key 1024
#输入密码,确认密码,自己随便定义,但是要记住,后面会用到。
#2.创建服务器证书的申请文件 server.csr
openssl req -new -key server.key -out server.csr
#输出内容为:
#Enter pass phrase for root.key: ← 输入前面创建的密码 
#Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN 
#State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音 
#Locality Name (eg, city) []:BeiJing ← 市的全名,拼音 
#Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名 
#Organizational Unit Name (eg, section) []: ← 可以不输入 
#Common Name (eg, YOUR name) []: ← 此时不输入 
#Email Address []:[email protected] ← 电子邮箱,可随意填
#Please enter the following ‘extra’ attributes 
#to be sent with your certificate request 
#A challenge password []: ← 可以不输入 
#An optional company name []: ← 可以不输入
#3.备份一份服务器密钥文件
cp server.key server.key.org
#4.去除文件口令
openssl rsa -in server.key.org -out server.key
#5.生成证书文件server.crt
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  1. 只允许 https的访问
server {
    listen    8010 ssl; #默认端口443,可以设为自己想要的端口
    server_name _;
    
    ssl_certificate /home/hayley/nginx/server.crt;	#证书
    ssl_certificate_key /home/hayley/nginx/server.key;	#私钥

    ……
}

  1. 同时支持http,https
# 可以同时支持http,https的访问,http会通过配置跳转到https(http 80跳转到https 443)
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
    ssl_certificate /path/to/signed_cert_plus_intermediates;
    ssl_certificate_key /path/to/private_key;
    #……
#重启nginx
service nginx start

参考:
nginx实现https网站设置
https://www.cnblogs.com/jingxiaoniu/p/6745254.html
Nginx配置Https
https://www.cnblogs.com/bincoding/p/6118270.html
Mozilla SSL Configuration Generator
https://mozilla.github.io/server-side-tls/ssl-config-generator/

你可能感兴趣的:(uWSGI,nginx)