Nginx + Uwsgi + django 部署
程序员文章站
2022-06-13 18:00:15
...
1. 安装 nginx
写道
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
sudo apt-get update
sudo apt-get install nginx
2. 安装 uwsgi
写道
sudo add-apt-repository ppa:stevecrozz/ppa
sudo apt-get update
sudo apt-get install uwsgi
sudo apt-get update
sudo apt-get install uwsgi
3. 安装 libxml2-dev
写道
sudo apt-get install libxml2-dev
4. 安装uwsgi-plugin-python
写道
sudo apt-get install uwsgi-plugin-python
5. 配置uwsgi.xml文件
写道
** 网上有很多如何配的文件, 这里不多写了 **
** 我用的django是1.6.4版本的,在项目APP下会自动创建一个wsgi.py文件,不需要手动再建 了,如有需要也请自行百度 **
<uwsgi>
<socket>127.0.0.1:8631</socket>
<master>true</master>
<pythonpath>..</pythonpath>
<module>wsgi</module>
<profiler>true</profiler>
<memory-report>true</memory-report>
<enable-threads>true</enable-threads>
<logdate>true</logdate>
<daemonize>/var/www/banbantong/files/logs/uwsgi.log</daemonize>
<limit-as>6048</limit-as>
</uwsgi>
<limit-as>6048</limit-as>
</uwsgi>
将uwsgi.xml放到与wsgi.py同级目录即可;
6. 启动uwsgi服务
写道
uwsgi -x /var/www/banbantong/BanBanTong/uwsgi.xml --plugin python
建议放到 /etc/rc.local 里随系统启动
7. 配置nginx
# cd /etc/nginx/sites-available
# sudo vim uwsgi && edit this
server {
listen 8100;
server_name 10.10.10.145;
access_log /var/log/nginx/uwsgi-access.log;
error_log /var/log/nginx/uwsgi-error.log;
location / {
root /var/www/banbantong;
uwsgi_pass 127.0.0.1:8631;
include uwsgi_params;
access_log off;
}
}
然后 链接到 sites-enabled
cd ../sites-enabled
sudo ln -s ../sites-enabled/uwsgi uwsgi
重启nginx : sudo /etc/init.d/nginx restart
8 . 开始访问吧 http://localhost:8100/
--------------------------------------------------------------
记得把项目放到pythonpath里,可以在wsgi.py加入下面代码
import os , sys
try:
sys.path.insert(0, os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))
except:
pass
下一篇: AngularJS压缩JS技巧分析
推荐阅读