Python虛擬環境安裝與配置專案啟動
阿新 • • 發佈:2019-01-09
一、概述
virtualenv,一個虛擬的python環境,一個專屬於專案的python環境。
二、安裝和配置
1.安裝虛擬環境
- 安裝:pip3 install virtualenv
- 建立:virtualenv venv -p /usr/bin/python3.5
- 進入:source venv/bin/activate
- 退出:deactivate
2.配置專案啟動系統服務(虛擬環境)
[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;
}
# custom....
location / {
try_files $uri @auth_success;
}
}