标签:www 文件 运行 pychar free nbsp listen dex etc
系统:CentOS7.2(阿里云ESC) 1。python版本,使用的是默认的python2.7 2。安装nginx,yum install -y nginx 3。安装virtualenv,yum install -y python-virtualenv 4。创建虚拟环境,virtualenv venv (venv为虚拟环境名称,可自行加上目录) 5。激活虚拟环境,source venv /bin/activate 6。在虚拟环境中安装gunicorn和flask,(venv) $ pipinstall gunicorn (venv) $ pip install flask 7。在目录/var/www中创建文件flask.py from flask import Flask def create_app(): app = Flask(__name__) return app app = create_app() if __name__ == ‘__main__‘: app.run() @app.route(‘/‘) def index(): return ‘<html>Hello world!</html>‘ 8。配置nginx,vim /etc/nginx/nginx.conf 添加配置 server{ listen 80; server_name 域名; location / { proxy_pass http://域名:801; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 9。启动gunicorn gunicorn -w 4 -b 0.0.0.0:801 flask:app
生成requirement文件:pip freeze > requirements.txt
根据requirement文件安装依赖库:pip install -r requirement.txt
标签:www 文件 运行 pychar free nbsp listen dex etc
原文地址:https://www.cnblogs.com/hedianzhan/p/9655183.html