Nginx, Uwsgi, Virtualenv and Django on Ubuntu 12.04

参考资料: http://eshlox.net/en/2012/09/11/nginx-uwsgi-virtualenv-and-django-ubuntu-1204/ https://virtualenv-chinese-docs.readthedocs.org/en/latest/ https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html http://www.virtualenv.org/en/latest/ 在virtualenv环境下安装 mysqldb的时候遇到几个问题 $ sudo apt-get install libmysqlclient-dev $ sudo apt-get install python-dev   把第一个链接的文章转过来,防止以后不能访问,其他几个都是官方文档,主要还是参考官方文档。 First install required applications.
sudo apt-get install nginx uwsgi uwsgi-plugin-python python-virtualenv
Versions of packages that will be used:
Nginx 1.1.19.1
Uwsgi 1.0.3+dfsg-1ubuntu0.1
Virtualenv 1.7.1.2-1
Django 1.4.1
Virtualenv. I store my project in ~/projects. Now I'm creating python virtual environment for my project and I'm installing Django.
cd ~/projects/
virtualenv eshlox.net
cd eshlox.net
source bin/activate
pip install django
django-admin.py startproject project
Nginx configuration. IMHO, by default, nginx is configured for basic tasks. I won't change this configuration in this entry. Configuration files are stored in /etc/nginx/sites-available. Go to this directory and create a new file.
cd /etc/nginx/sites-available
vim eshlox.net
It's example configuration.
server {
    listen  80;
    server_name eshlox.net www.eshlox.net;
    access_log /var/log/nginx/eshlox.net_access.log;
    error_log /var/log/nginx/eshlox.net_error.log;

    location / {
        uwsgi_pass  unix:///tmp/eshlox.net.sock;
        include     uwsgi_params;
    }

    location /media/  {
        alias /home/eshlox/projects/eshlox.net/project/project/media/;
    }

    location  /static/ {
        alias  /home/eshlox/projects/eshlox.net/project/project/static/;
    }
}
We must create symlink to enable this.
cd /etc/nginx/sites-enabled
ln -s ../sites-available/eshlox.net .
Uwsgi. Like with Nginx.. configuration files are stored in /etc/uwsgi/apps-available. Go to this directory and create a new file.
cd /etc/uwsgi/apps-available
vim eshlox.net.ini
[uwsgi]
vhost = true
plugins = python
socket = /tmp/eshlox.net.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/eshlox/projects/eshlox.net/project/project/wsgi.py
virtualenv = /home/eshlox/projects/eshlox.net
chdir = /home/eshlox/projects/eshlox.net/project
touch-reload = /home/eshlox/projects/eshlox.net/project/reload
Enable this.
cd /etc/uwsgi/apps-enabled/
ln -s ../apps-available/eshlox.net.ini .
That's all. Now, run this services.
sudo service nginx start
sudo service uwsgi start
Of course, this is a very basic configuration. Change it according to your needs.

上一篇:
下一篇:

相关文章:

Categories: 博客记录

0 Responses so far.

Leave a Reply