""" WSGI config for HelloWorld project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ """ import os,sys os.environ['PYTHON_EGG_CACHE'] = '/data/wwwroot/HelloWorldroot/.python-eggs' reload(sys) from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "HelloWorld.settings") application = get_wsgi_application() if __name__ == "__main__": HelloWorld.run()
演示的是django HelloWorld项目启动,上面的是位于/data/wwwroot/HelloWorldroot/HelloWorld/wsgi.py
[uwsgi] #socket = 127.0.0.1:9666 #设置监听的端口 socket = /tmp/HelloWorld_uwsgi.sock #设置使用sock #修改文件后自动重启,触发时间3秒 py-autoreload=3 pidfile=/tmp/HelloWorld-master.pid master=true vhost=true #项目目录 chdir=/data/wwwroot/HelloWorldroot/ module=HelloWorld.wsgi
#最大请求数 max-requests = 5000
#启动的用户
gid=www
uid=www
uwsgi_read_timeout=600 # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间,单位秒。
harakiri=1200 #请求超时时间,单位秒
上面的是位于/data/wwwroot/HelloWorldroot/uwsgi.ini
配置supervisor
vi /etc/supervisord.d/HelloWord.ini
[program:HelloWord] user=root command=/usr/local/bin/uwsgi /data/wwwroot/HelloWorldroot/uwsgi.ini -l 128 -p 400 --buffer-size 32768 #l 设置套接字侦听队列大小,-p 生成指定数量的workers/processes,buffer-size uwsgi包解析的内部缓存区大小#检测进程停止的信号 stopsignal=QUIT #启动supervisord的时候自动启动 autostart=true autorestart = true redirect_stderr=true stdout_logfile=/data/wwwroot/HelloWorldroot/uwsgi.log stderr_logfile=/data/wwwroot/HelloWorldroot/uwsgi_error.log
supervisorctl reload #重新加载配置
supervisorctl status 查看启动状态
使用socket = /tmp/HelloWorld_uwsgi.sock 则使用代理访问,监听端口可以直接访问端口
nginx 配置
server { listen 80; server_name 域名; access_log /data/wwwroot/HelloWorldroot/logs/access.log; error_log /data/wwwroot/HelloWorldroot/logs/error.log; location / { include uwsgi_params;
#uwsgi_pass 127.0.0.1:9666; uwsgi_pass unix:/tmp/HelloWorld_uwsgi.sock; } #静态文件路径 location /static/ { alias /data/wwwroot/HelloWorldroot/HelloWorld/static/; } }