Ubuntu 14.04+django 1.7.1+NGINX+UWSGI Deployment Tutorial _python

Source: Internet
Author: User
Tags django server virtualenv

Specific environment:
Ubuntu 14.04 Python 2.7.6 Django 1.7.1 virtualenv name:test Nginx

Suppose the project folder is located in the/data/www/ts setting in the./conf

Copy Code code as follows:

Virtualenv name = Test
Domain name = example.com

Django+uwsgi's deployment is really too much pain. There appears to be a new version of compatibility issues with existing tutorials on the web. Finally ran to Uwsgi official online to find the tutorial finally ran through the.
However, the official website of the tutorial seems to have a guiding nature of teaching, deployment of the time seems to be a detour, where the record down to streamline content

Http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

First of all, need a uwsgi_params file, placed in the project's Conf folder inside. Then you need to point to it. The contents of the document are as follows:

Copy Code code as follows:

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;

Create a file called ts_nginx.conf, which reads

Copy Code code as follows:

# ts_nginx.conf

# The upstream component Nginx needs to connect to
Upstream Django {
# server Unix:///path/to/your/mysite/mysite.sock; # for a file socket
Server 127.0.0.1:8001; # for a Web port socket (we'll use this
}

# Configuration of the server
server {
# The Port your site is served on
Listen 80;
# The domain name it'll serve for
server_name. example.com; # 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/data/www/ts/media; # your Django project ' s media files-amend as required
}

location/static {
alias/data/www/ts/static; # your Django project ' s static files-amend as required
}

# Finally, send all Non-media requests to the Django server.
Location/{
Uwsgi_pass Django;
Include/data/www/ts/conf/uwsgi_params; # The Uwsgi_params file for you installed
}
}

Connect this conf file to the Nginx search directory.

Copy Code code as follows:

sudo ln-s/data/www/ts/conf/ts_nginx.conf/etc/nginx/sites-enabled/

Prerequisites: This is where you set up the Django project's settings, static files.

Copy Code code as follows:

Static_root = Os.path.join (Base_dir, "static/")
And then run

Python manage.py collectstatic

After:

Copy Code code as follows:

Service Nginx Restart

You should be able to see
Http://example.cn:8000/media/1.gif
(Put in a static file beforehand)

After the BlaBla steps are nonsense, jump here:

Copy Code code as follows:

Configuring Uwsgi to run with a. ini file

Ts_uwsgi.ini in the project root directory

Copy Code code as follows:

[Uwsgi]
# django-related Settings
# The base directory (full path)
ChDir =/data/www/ts
# Django ' s Wsgi file
module = Ts.wsgi
# The Virtualenv (full path)
Home =/root/.envs/test
# process-related Settings
# Master
Master = True
# Maximum number of worker processes
processes = 10
# The socket (use the full path to is safe
Socket = 127.0.0.1:8001
# ... with appropriate permissions-may to be needed
# Chmod-socket = 664
# Clear Environment on exit
Vacuum = True
# Set an environment variable
env = Django_settings_module=conf.settings
Uwsgi--ini Mysite_uwsgi.ini # The--ini option is used to specify a file

Here environment variable set env need Conf folder has init.py, otherwise conf will not be considered as module

(Currently, in addition to port 80, other ports are accessible via address: port.) Have tested 8000,81.80 test do not know why not. To be continued tomorrow)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.