- 配置虚拟环境
mkdir /home/edc/myproject
cd /home/edc/myproject
virtualenv myprojectenv
source myprojectenv/bin/activate
- Demo文件,/home/edc/myproject/myproject.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<h1 style='color:blue'>Hello There!</h1>"
if __name__ == "__main__":
app.run(host='0.0.0.0')
- wsgi入口点 /home/edc/myproject/wsgi.py
from myproject import app
if __name__ == "__main__":
app.run()
- 配置ini文件 /home/edc/myproject/myproject.ini
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = myproject.sock
chmod-socket = 660
vacuum = true
die-on-term = true
- 创建系统启动文件 /etc/systemd/system/myproject.service
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/home/edc/myproject
Environment="PATH=/home/edc/myproject/myprojectenv/bin"
ExecStart=/home/edc/myproject/myprojectenv/bin/uwsgi --ini myproject.ini
[Install]
WantedBy=multi-user.target
- 启动
sudo systemctl start myproject
sudo systemctl enable myproject
sudo systemctl status myproject
- nginx配置 /etc/nginx/conf.d/myproject.conf
server {
listen 80;
server_name your_domain www.your_domain;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/edc/myproject/myproject.sock;
}
}
- 重新启动nginx
nginx -t
systemctl restart nginx
参考:参考
来源:oschina
链接:https://my.oschina.net/u/2351685/blog/3191952