gunicorn|daphne程序
gunicorn配置文件
# gunicorn.pyimport loggingimport logging.handlersfrom logging.handlers import WatchedFileHandlerimport osimport multiprocessing#进程名proc_name = 'gunicorn_项目名_project' bind = "0.0.0.0:12222"max_requests = 5000# 设置gunicorn使用的python虚拟环境pythonpath='/home/chenxinming/项目名//venv/bin/python3'timeout = 300user = 'root'group = 'root'# 默认为False。此设置用于开发,每当应用程序发生更改时,都会导致工作重新启动。reload = true# 设置环境变量raw_env=['APE_API_ENV=DEV']pidfile = '/tmp/zwy-gunicorn.pid'backlog = 512 #监听队列chdir = '/home/test/server/bin' #gunicorn要切换到的目的工作目录worker_class = 'gevent' #使用gevent模式,还可以使用sync 模式,默认的是sync模式workers = multiprocessing.cpu_count() * 2 + 1 #进程数threads = 2 #指定每个进程开启的线程数loglevel = 'info' #日志级别,这个日志级别指的是错误日志的级别,而访问日志的级别无法设置access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"' #设置gunicorn访问日志格式,错误日志无法设置"""其每个选项的含义如下:h remote addressl '-'u currently '-', may be user name in future releasest date of the requestr status line (e.g. ``GET / HTTP/1.1``)s statusb response length or '-'f referera user agentT request time in secondsD request time in microsecondsL request time in decimal secondsp process ID"""accesslog = "/home/test/server/log/gunicorn_access.log" #访问日志文件errorlog = "/home/test/server/log/gunicorn_error.log" #错误日志文件
upstream django { ip_hash; server 127.0.0.1:8000;}server { listen 80 default; server_name xxxxx.com; keepalive_timeout 70; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 60; client_max_body_size 500m; client_body_buffer_size 128k; proxy_pass django; }}
uwsgi程序
uwsgi配置文件
[uwsgi]# 设置python程序名称py-program-name='django—project'#使用nginx连接时使用,如果不连接nginx,注释该选项socket = 127.0.0.1:50000chmod-socket = 664#作为web服务器使用,也就是通过http访问,如果使用nginx,注释该选项,使用socket链接#http = :8000#项目的文件目录chdir = /python_test/Fresh_every_day#项目中wsgi文件所在地址,相对于项目的文件目录地址wsgi-file = Fresh_every_day/wsgi.py#启动的进程数量processes = 4#每个进程启动的线程数量,由于GIL锁,此选项鸡肋threads = 2#允许主进程存在master = true#在指定地址上开启服务状态#使用nc 127.0.0.1 1717stats = 127.0.0.1:9090# 允许程序后台允许,并且日志文件保存在哪里,使用了supervisor就不要再让uwsgi后台了,否则会出现uwsgi杀不死的bug# daemonize = /home/log/uwsgi.log#程序运行时主进程的uwsgi.pid保存在此文件内pidfile = /tmp/uwsgi.pid#当服务器退出的时候自动清理环境,删除unix socket文件和pid文件vacuum = true# 将会每2秒检查一次python模块的改动,自动重启。py-autoreload = 2#日志最大log-maxsize = 50000000#只保存错误请求数据# disable-logging = true#env虚拟环境所在路径(两种都可以)home = /path/to/virtualenv #这是官网写的virtualenv = /root/.virtualenvs/Fresh_every_day #另一种方式#启用线程enable-threads = true#一个请求花费的时间超过了这个harakiri超时时间,那么这个请求都会被丢弃,#并且当前处理这个请求的工作进程会被回收再利用(即重启)harakiri = 60#设置默认缓冲区大小,接受一个拥有很多请求头的大请求,最多可到64k#buffer-size = 65536#设置静态文件#static-map = /static=//www/wwwroot/mysite/static#gevent协程支持,最大100个, 不推荐使用协程,有连接不到redis的BUG#gevent=100#gevent协程补丁,会抛出下方的警告,补丁慎打,这个项目打了这个补丁无法登录了....#MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to#errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on#Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016.#Modules that had direct imports (NOT patched):#['urllib3.util (/root/.virtualenvs/Fresh_every_day/lib/python3.6/site-packages/urllib3/util/__init__.py)',#gevent-monkey-patch=true#gevent-early-monkey-patch=true#添加雷锁,防止惊群现象thunder-lock=true
upstream django { server 0.0.0.0:50000;}server { listen 80; server_name pythonav.cn; #访问nginx的根路径时,转发请求给uwsgi的8000端口,这里要和uwsgi.ini写的一致 location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 60; client_max_body_size 500m; client_body_buffer_size 128k; include uwsgi_params; uwsgi_pass django; }}