Python虚拟环境安装与配置项目启动

一、概述

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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值