阿里轻量应用服务器+django+uwsgi+nginx+https项目部署小记

 

 

参考:    https://blog.csdn.net/watsy/article/details/9247967

 

sudo apt-get update
sudo apt-get install zlib1g
sudo apt-get install zlib1g-dev


----------------------------------安装MySQL-------------------------------------

关于修改数据库设置远程连接
https://blog.csdn.net/junqing124/article/details/53180874?utm_source=blogxgwz0
关于安装mysqlclient报错找不到mysql_conf问题
https://www.cnblogs.com/fwl8888/p/9346338.html

----------------------------------python3.6.6-----------------------------------下载python3.6.6

wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz

tar -xvf Python-3.6.6.tar.xz

cd Python-3.6.6

#启用优化
./configure --enable-optimizations

#这一步很耗时
make

make install


#更新pip版本
python3 -m pip install --upgrade pip

------------------------------------virtualenv----------------------------------

安装虚环境

sudo apt-get install python2.7 python2.7-dev
sudo apt-get install virtualenv
sudo apt-get install virtualenvwrapper

echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
echo "source /usr/share/virtualenvwrapper/virtualenvwrapper.sh" >> ~/.bashrc

source ~/.bashrc

mkvirtualenv envs

先创建许环境   再往下执行

.................................................................................

#1基本命令  

#a查看当前的虚拟环境目录
workon +tab+tab

#b切换到虚拟环境
workon 虚拟环境名
  
#c退出虚拟环境
deactivate

#d删除虚拟环境
rmvirtualenv venv

------------------------------------uWSGI---------------------------------------

#Python uwsgi 安装配置

pip install uwsgi
apt-get install build-essential python-dev  依赖

#测试uwsgi是否可成功运行:
#新建个test.py文件
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"]

uwsgi --http :9090 --wsgi-file test.py

访问ip:9090 页面输出"Hello World"则表示成功

 在项目根目录新建"uwsgi.ini"

[uwsgi]
#http=0.0.0.0:8889
socket=0.0.0.0:9656
chdir=/home/XinHeServer
wsgi-file=/home/XinHeServer/XinHeServer/wsgi.py
processes=1
threads=1
master=True
home=/root/.virtualenvs/envs
pythonpath=/root/.virtualenvs/envs/lib/python3.6/site-packages
pidfile=uwsgi.pid
daemonize=/home/logs/uwsgi_log/uswgi.log
vacuum=true
uwsgi_read_timeout=600
buffer-size     =65535

cd 到uwsgi.ini的目录  运行: uwsgi --ini uwsgi.ini
-------------------------------------Nginx---------------------------------------


首先需安装nginx依赖库

1.安装gcc g++的依赖库
apt-get install build-essential
apt-get install libtool


2.安装pcre依赖库
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev


3.安装zlib依赖库
apt-get install zlib1g-dev


4.安装ssl依赖库
apt-get install openssl

 https的话直接去申请一年的免费证书然后给你一个key 下载这俩文件  1541069125642.pem    1541069125642.key    就这俩玩意   阿里官方教程已经很详细了   然后把东西配到你的nginx就好了 .

 

接着就是把你的80端口定向到443去      

也就是用户访问你的网站时默认是到80 的  ,

而你的https却是443端口

所以需要重定向一下就OK了

#nginx 配置

    server {  
        listen  80;  
        server_name 你的网址;  
        rewrite ^(.*)$  https://$host$1 permanent;  
    }  
    gzip_disable "msie6";

#https配置
    server {
        listen 443;
        server_name 你的网址;
        ssl on;
        charset     utf-8;
        client_max_body_size 3M;
        root html;
        access_log  /home/logs/nginx_log/xinhe_access.log;
        error_log   /home/logs/nginx_log/xinhe_error.log;
        index index.html index.htm;
        ssl_certificate   cert/1541069125642.pem;
        ssl_certificate_key  cert/1541069125642.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 /media  {
            alias /home/XinHeServer/media;
        }
        location /static {
            alias /home/XinHeServer/static;
        }
        location / {
            include uwsgi_params;
            #同uwsgi内容
            uwsgi_pass 0.0.0.0:9656;
            #链接超时时间
            uwsgi_read_timeout 60;
        }
    }


人老易忘,做此记录.

 

 

 

 

 

 

------------------------------------------------------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章