项目上线阿里云并配置ssl证书实现https访问

Django项目上线配置:
在NGINX的安装目录下创建一个cert文件夹,将你申请的证书下载下来上传到里面。
nginx文件配置:

server{
		#https监听端口
        listen 443;
        #服务名写你的域名
        server_name www.user-name-chao.xyz;
        ssl on;
        #你申请的证书路径
        ssl_certificate /etc/nginx/cert/1757169_user-name-chao.xyz.pem;
        ssl_certificate_key /etc/nginx/cert/1757169_user-name-chao.xyz.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers on;
		#你配置的监听uwsgi端口
        location / {
                # 转发端口必须和uconfig.ini中socket端口一致
                uwsgi_pass      127.0.0.1:8000;
               include uwsgi_params;
        }
        # 静态资源所在位置
        location /static {
                alias /var/www/Bloger/static/;
        }
    }

这些其实在你申请证书的时候阿里云会有教你怎么安装证书的,下边是阿里云的教程链接:https://help.aliyun.com/knowledge_detail/95491.html?spm=5176.2020520154.cas.25.21de56a7FzQrKs

在你的项目根目录下创建uwsgi配置文件,具体配置内容如下:

[uwsgi]

# 外部访问地址,可以指定多种协议,现在用http便于调试,之后用socket  #
socket = 127.0.0.1:8000 # uwsgi的监听端口

# 指向项目根目录
chdir =  /var/www/Bloger
# wsgi.py所在位置
wsgi-file = Bloger/wsgi.py
#你的项目名字+.wsgi
module = Bloger.wsgi
# 虚拟开发环境位置
virtualenv = /root/.pyenv/versions/blog_env
#plugins = python

master = true

# 处理器数
processes = 1

# 线程数
threads = 2

flask项目上线配置,跟Django基本一样:
nginx:

server{
        server_name (你的域名);
        listen 80;
        listen 443;
        ssl on;
        ssl_certificate   /etc/nginx/cert/(你的证书名).pem;
        ssl_certificate_key  /etc/nginx/cert/(密钥文件名).key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
          uwsgi_pass      127.0.0.1:8000;
          include uwsgi_params;
        }
        location /static {
                alias /var/www/flask/static;
                }
        }

uwsgi:

[uwsgi]
  socket = 127.0.0.1:8000
  #你项目的运行文件名
  wsgi-file = manage.py
  #你项目的可调用实例化对象
  callable = app
  #这个是为了能够使其在服务器后台运行
  daemonize = /var/log/uwsgi.log

后边会继续跟进一个服务器配置多个项目,还在搞…

你可能感兴趣的:(项目上线)