一、概述
virtualenv,一个虚拟的python环境,一个专属于项目的python环境。
二、安装和配置
1.安装虚拟环境
- 安装:pip3 install virtualenv
- 创建:virtualenv venv -p /usr/bin/python3.5
- 进入:source venv/bin/activate
- 安装gunicorn:pip install gunicorn
- 安装gevent:pip install gevent
- 退出:deactivate
2.配置项目启动系统服务(虚拟环境)
- 创建目录
mkdir /run/gunicorn
- service
[Unit]
Description=mc iotapios service
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/home/workspace/iotapios
Environment="PATH=/home/workspace/iotapios/venv/bin"
ExecStart=/home/workspace/iotapios/venv/bin/gunicorn --bind unix:/run/gunicorn/iot.sock -k gevent iotapios.wsgi
[Install]
WantedBy=multi-user.target
3.配置nginx.conf
upstream iotserver{
server unix:/run/gunicorn/iot.sock fail_timeout=0;
}
server {
listen 443 ssl ;
server_name www.example.com;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
ssl_session_tickets off;
# auth let's encrypt SSL
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /home/workspace/www;
}
location = /.well-known/acme-challenge/ {
return 404;
}
location @auth_success {
proxy_set_header Host $http_host;
proxy_pass http://iotserver;
}
# custom....
location / {
try_files $uri @auth_success;
}
}