1. 运行环境
Linux: centos 7.4 64位
python: python 3.4
2. 安装python虚拟环境virtualenv
$easy_install virtualenv $mkdir venv $cd venv$virtualenv -p python venv_f # 由于本机服务器的python3已经软连接到了python 所有这里-p 后面的参数直解释python虚拟环境下python版本3.4
创建项目目录/home/app/FV_Blog,新增一个hello.py文件
# hello.py from flask import Flask app=Flask(__name__) @app.route('/hello') def hello_world(): return "Hello World" @app.route('/user/<name>') def hello_user(name): return "<h1>Hello %s ~</h1>" % name if __name__=='__main__': from werkzeug.contrib.fixers import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app) app.run()gunicorn -b 127.0.0.1:5000 hello:app这里注意一下两个参数,hello flask启动文件的文件名称, app是实例化flask的变量。
找到你的nginx配置文件的位置
备份一份出来,将nginx.conf里server部分修改成如下:
server { listen 8080; server_name _; # 这是HOST机器的外部域名,用地址也行 root /home/app/FV_Blog; location / { proxy_pass http://127.0.0.1:5000; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }然后重启nginx
$service nginx restart
转载于:https://www.cnblogs.com/XIII-UP/p/8269674.html
