第一步打开服务器找到nginx目录文件,找到nginx.conf文件进行配置
我们只需要找到http所在的那个服务加入一行代码
return 301 $request_uri;
就可以将http协议改成https
http{include mime.types;server{charset utf-8;listen 443 ssl;#端口server_name ; #网站域名index index.html ;root /opt/Blog/MyBlog;location /static {alias /opt/Blog/qwe/static; }location /media {alias /opt/Blog/qwe/media; }# Finally, send all non-media requests to the Django server.location / {uwsgi_pass 127.0.0.1:81;include/opt/Blog/qwe/uwsgi_params; }ssl_certificate bmftbmt.site_bundle.crt;#这几个是对ssl证书进行配置ssl_certificate_key .key;ssl_session_timeout 5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;ssl_prefer_server_ciphers on;}server{charset utf-8;listen 80;server_name ;index index.html ;root /opt/Blog/qwe;return 301 $request_uri; #例如:将重定向到location /static {alias /opt/Blog/qwe/static; }location /media {alias /opt/Blog/qwe/media; }location / {uwsgi_pass 127.0.0.1:81;include/opt/Blog/qwe/uwsgi_params; }}}
原文链接-白树谷博客https://www.bmftbmt.site/blog/50/