Server configuration is Ubuntu14.04 64-bit OS
The ubuntu14.04 default is to install the python2.7 version without installing it yourself.
First update the next source
sudo apt-get update
The first step is to install PIP first
sudo apt-get install-y python-pip
There are times when you need to install several related packages before installing PIP
sudo apt-get install-y Python-dev
sudo apt-get install-y Libevent-dev
After installing PIP we started to install Django
sudo pip install django==1.7.1
After installation enter Python into the interactive environment input Django. Version View versions
Start loading Uwsgi
The following may be the relevant packages
sudo apt-get install-y build-essential
sudo apt-get install-y Zliblg-dev
sudo apt-get install-y Libsqlite3-dev
sudo apt-get install-y Libreadline6-dev
sudo apt-get install-y Libgdbm-dev
sudo apt-get install-y Libbz2-dev
sudo apt-get install-y Tk-dev
sudo apt-get install-y Uwsgi-plugin-python
Installing UWSGI
sudo pip install Uwsgi
You can write a test.py.
#test.pydefapplication (env, Start_response): Start_response ('OK', [('Content-type','text/html')]) return[b"Hello World"]#Python3 #return ["Hello World"] # Python2
Input uwsgi--http:8000--wsgi-file test.py
Browser input http://example.com:8000 See if HelloWorld is displayed
Install Git again
sudo apt-get install-y git
Cloning a project
Start a project with Uwsgi
Uwsgi--ini ${current_path}${sep}/$uwsgi _name
Installing Nginx
sudo apt-get install-y nginx
Modify Nginx configuration file, delete the contents of the original package, plus soft link
Ln-s ${current_path}${sep}${p_name}${sep}${conf_name}/etc/nginx/sites-enabled/
Service Nginx Restart
Enter the URL to do so.
In addition, you need
Python manage.py collectstatic
Import OS
Base_dir = Os.path.dirname (Os.path.dirname (__file__))
Static_root = Os.path.join (Base_dir, ' Static2 ',). replace (' \ \ ', '/')
Static_url = '/static/'
Then move the static file from Static2 to the static directory
Enter the URL to do so.
Several configuration files:
Nginx.conf:
# The upstream component Nginx needs to connect Toupstream Django {server unix:/etc/nginx/django/daowang/wangdao.sock; # for a file socket}# configuration of the serverserver {# The Port your site would be is served on listen 80; # The domain name it would serve for server_name http://114.215.157.15/; # 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/etc/nginx/django/daowang/static/media; # your Django project ' s media files-amend as required} location/static {alias/etc/nginx/django/daowang/ Static # your Django project ' s static files-amend as required} location/fingerhire{Proxy_pass http://127.0.0.1: 8080; } # Finally, send all Non-media requests to the Django server. Location/{Uwsgi_pass Django; Include/etc/nginx/django/daowang/uwsgi_params; # The Uwsgi_params File you installed}}
Uwsgi.ini
[uwsgi]# django-related settings# the base directory (full path) chdir =/etc/nginx/django/daowang# Django ' s Wsgi file Module = wangdao.wsgi# mastermaster = true# Maximum number of worker processesprocesses = 32max-requests = 1000# The socket (use the full path to be safesocket =/etc/nginx/django/daowang/wangdao.sock# ... with APPROPR Iate Permissions-may is neededchmod-socket = 666#chown-socket = www-data:www-data# clear Environment on Exitvac Uum = truedaemonize =/var/log/uwsgi/wangdao.logpidfile =/tmp/project-master.pid# Added 2014-09-17reload-on-as = 126reload-on-rss = 126enable-threads = Truepythonpath =/etc/nginx/ Django/daowang
Uwsgi_params
Uwsgi_param query_string $query _string;uwsgi_param request_method $request _method;uwsgi_param content_type $content _type;uwsgi_param content_length $content _length;uwsgi_param REQUEST _uri $request _uri;uwsgi_param path_info $document _uri;uwsgi_param document_root $ Document_root;uwsgi_param server_protocol $server _protocol;uwsgi_param HTTPS $https if_not_ Empty;uwsgi_param remote_addr $remote _addr;uwsgi_param remote_port $remote _port;uwsgi_ param server_port $server _port;uwsgi_param server_name $server _name;
Configure the wsgi.py under the root directory
Import Osos.environ.setdefault ("django_settings_module"" Wangdao.settings")fromimport= get_wsgi_application ()
Common commands:
1. View Port usage:
Netstat-lpnt
2. kill all Uwsgi processes
Killall-9 Uwsgi
3.uwsgi Start command
Uwsgi--ini/etc/nginx/django/lovep2c/lovep2c_uwsgi.ini
4. Close the uwsgi command
Uwsgi--stop/tmp/project-master.pid
5. Restart the uwsgi command
Uwsgi--reload/tmp/project-master.pid
nginx error log:
Tail/var/log/nginx/error.log
Uwsgi log:
Tail/var/log/uwsgi/lovep2c.log
Project error log:
Tail/etc/nginx/django/debug.log
Tail/etc/nginx/django/error.log
Ubuntu under Configuration Nginx+uwsgi+django