uwsgi与nginx配置启动

最后都变了- 提交于 2020-03-11 19:26:40
  1. 配置虚拟环境
mkdir /home/edc/myproject
cd /home/edc/myproject
virtualenv myprojectenv
source myprojectenv/bin/activate
  1. 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')

  1. wsgi入口点 /home/edc/myproject/wsgi.py
from myproject import app

if __name__ == "__main__":
    app.run()
  1. 配置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
  1. 创建系统启动文件 /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
  1. 启动
sudo systemctl start myproject
sudo systemctl enable myproject
sudo systemctl status myproject
  1. 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;
    }
}
  1. 重新启动nginx
nginx -t
systemctl restart nginx

参考:参考

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!