以下默认已经部署好了django+uwsgi+nginx, 如果没有部署好,可以参考我的另一篇文章https://blog.csdn.net/qq_31769869/article/details/108731525
- 在/etc/nginx目录下创建cert文件夹,将阿里云或者其他方式得到的pem和key保存在这个文件夹,证书可以在阿里云免费获得。
- 修改之前在nginx.conf编辑的server
server{
listen 80;
server_name maxniu.xyz www.maxniu.xyz;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/nginx/cert/5677000_www.maxniu.xyz.pem;
ssl_certificate_key /etc/nginx/cert/5677000_www.maxniu.xyz.key;
server_name maxniu.xyz www.maxniu.xyz;
server_name www.maxniu.xyz;
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8001;
uwsgi_read_timeout 2000;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/dzsw/mysite/static/;
}
}
其中第一个server目的是永久重定向,第二个是修改后的结果。配好后就可以了。