Django + Nginx + Uwsgi 配置服务器
Django
tar -zxvf Django-1.6.11.tar.gz
cd Django-1.6.11
python setup.py install
django-admin.py startproject ~/jiarenyf
cd ~/jiarenyf
python manage.py startapp ydf
python manage.py runserver 0.0.0.0:4567
Uwsgi
sudo apt-get install python-dev pip
sudo pip install uwsgi
cd ~/jiarenyf
uwsgi --http :4567 --chdir ~/jiarenyf --module ydf.uwsgi
<uwsgi>
<socket>/dev/shm/ydf.sock</socket>
<chdir>~/jiarenyf</chdir>
<module>ydf.wsgi</module>
<processes>4</processes>
<enable-threads/>
<chmod-socket>666</chmod-socket>
<listen>1024</listen>
</uwsgi>
vim /etc/sysctl.conf
net.core.somaxconn=1024
sysctl -p
Nginx
sudo apt-get install nginx
vim ~/jiarenyf/jiarenyf/settings.py
STATIC_ROOT=~/jiarenyf/ydf/static
cd ~/jiarenyf
python manage.py collectstatic
# 文件路径:~/jiarenyf/nginx/ydf_nginx.conf
upstream ydf_django{
server unix:
# server 127.0.0.1:9000;
# 二选一,要与~/jiarenyf/uwsgi/ydf_socket.xml中socket对应
}
server{
listen 4567;
server_name 0.0.0.0;
charset utf-8;
client_max_body_size 5M;
access_log ~/jiarenyf/nginx/access.log;
error_log ~/jiarenyf/nginx/error.log;
location /{
include /etc/nginx/uwsgi_params;
uwsgi_pass ydf_django;
}
location /static{
alias ~/jiarenyf/ydf/static;
}
location /media{
alias ~/jiarenyf/ydf/media;
}
}
sudo ln ~/jiarenyf/nginx/ydf_nginx.conf -s /etc/nginx/site-enabled
sudo service nginx restart