周末趁着加班空闲,找了一个旧机器,装了个ubuntu13.04,以后就可以用它来做我在公司的git 以及web服务器,顺便在它上面编译一下android源码,哈哈,很爽。
先说web系统,最进一直在捣鼓Django,之前用apache2+apache2-python-mod搭了一个简易版本的服务器,用起来感觉不爽,直接换成nginx和uwsgi
1.6.2
是的版本,这种写法在bae的
requirements.txt中也有体现,比如需要安装django,可以用==,>,<等比较操作符来选择版本号。
wsgi的全称是Web Server Gateway Interface,通过$django-admin.py startproject mysite
会生成一个wsgi.py的文件,里面定义了一个application变量,uwsgi服务的对象就是它。
/static/
以及
/media/
的服务器。因此我们需要配合使用nginx作为web服务器来处理/static/以及/media/的请求,而它其他的页面请求都转交给uwsgi来处理。
mysite_uwsgi.ini
(名称可随意)[uwsgi] # Django-related settings # the base directory (full path) chdir = /path/to/your/project # Django's wsgi file module = dijkstra.wsgi plugin = python # process-related settings # master master = true # maximum number of worker processes processes = 5 # the socket socket = /path/to/your/project # ... with appropriate permissions - may be needed chmod-socket = 666 # clear environment on exit vacuum = true
根据uid的不同可以设置不同的socket权限,如果权限设置不当,uwsgi可能会出现permmision denied的错误。
mysite_nginx.conf
文件# dijkstra_nginx.conf # the upstream component nginx needs to connect to upstream django { server unix:///home/lyndon/github/Mathematician/dijkstra/dijkstra.socket; # server 127.0.0.1:8001 } # Configuration of the server server { # the port your site will be served on listen 8000; # the domain name it will serve for server_name x.x.x.x # substitute your machine's IP address or FQDN charset utf-8 # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /path/to/your/project/media; } location /static { alias /path/to/your/project/static; } # Finally. send all non-media requests to the Django server location / { uwsgi_pass django; include /path/to/your/project/uwsgi_params; } }
uwsgi_params
考到工程目录下cp /etc/nginx/uwsgi_params /path/to/your/project/
# SECURITY WARNING: don't run with debug turned on in production! DEBUG = False TEMPLATE_DEBUG = False ALLOWED_HOSTS = ['x.x.x.x', 'localhost'] # substitute your machine's IP address or FQDN
$sudo service uwsgi start
$sudo service uwsgi stop
$sudo service uwsgi restart
$sudo service nginx start
$sudo service nginx stop
$sudo service nginx restart