cd /usr/ports/www/nginx/ && make install clean
cd /usr/ports/www/uwsgi/ && make install clean
### /etc/rc.conf
nginx_enable="YES"
uwsgi_enable="YES"
uwsgi_flags="-M -L -p 2 --vhost"
# Add the following lines to /etc/rc.conf to enable uwsgi:
# uwsgi_enable (bool): Set it to "YES" to enable uwsgi
# Default is "NO".
# uwsgi_socket (path/str): Set the path to the uwsgi unix socket
# Default is /tmp/uwsgi.sock.
# uwsgi_logfile (path): Set the path to the uwsgi log file
# Default is /var/log/uwsgi.log.
# uwsgi_pidfile (path): Set the path to the uwsgi pid file
# Default is /var/run/uwsgi.pid.
# uwsgi_uid (int): Set the UID of the process to run with
# Default is 80.
# uwsgi_gid (int): Set the GID of the process to run with
# Default is 80.
# uwsgi_flags (str): Set the uwsgi command line arguments
# Default is "-M -L".
#uwsgi -s /tmp/uwsgi.sock -C -M -p 4 -t 30 --limit-as 128 -R 10000 --vhost
#-s 表示用 unix socket 方式执行 uwsgi,
#-C 表示将 /tmp/uwsgi.sock 文件权限改成 666 以便 nginx 可以读取,
#-M 表示启动管理进程,
#-p 4 表示预生成 4 个 worker 子进程,
#-t 30 是 cgi 程序超时,
#--limit-as 128 表示限制内存最大 128M,
#-R 10000 表示每个 worker 处理的最大请求数,
#--vhost 表示启用虚拟服务器,
### /usr/local/etc/nginx/site-wjlcom.conf
server {
listen 80;
server_name d.com;
location / {
uwsgi_pass unix:/tmp/uwsgi.sock;
uwsgi_param UWSGI_CHDIR /home/wjl/wjlcom;
uwsgi_param UWSGI_SCRIPT uwsgi_django;
include uwsgi_params;
}
location ^~ /app/static/ {
alias /home/wjl/wjlcom/static/;
access_log off;
expires 30d;
}
}
###uwsgi_bottle.py
from bottle import route, run, static_file, app
@route('/')
def index(name='World'):
return '<b>Hello %s!</b>' % name
@route('/hello/:name')
def hello(name='World'):
return '<b>Hello %s!</b>' % name
@route('/static/<filename>')
def server_static(filename):
return static_file(filename, root='static')
if __name__ == "__main__":
# Interactive mode
run(host='localhost', port=8000, reloader=True)
else:
# Mod WSGI launch
application = app()
###uwsgi_django.py
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
| 菲平&菲凡档案 版权所有@2010 wangjinling.com 3.5beta 20100220 update | Python,PostgreSQL,FreeBSD,jQuery |
![]() |