Nginx+uwsgi Deploying Django

Source: Internet
Author: User

Pre-installed: Nginx, Django

Django Site Tree

| Site

|-----Blog (self-built project)

|-----manage.py

|-----Site (setting URL Wsgi ...)

| |-----wsgi.py

|-----static

| |-----JS

| |-----CSS

|-----uwsgi.log

|-----uwsgi-socket.xml

1. LIBXML2, Libxml2-devel, Uwsgi

 1.1 Installation

Note: You must first install LIBXML2, Libxml2-devel, and then install Uwsgi

RPM–IVH libxml2*****

Pip:pip Install Uwsgi

Tar:python Setup.pu Install

1.2 Test Uwsgi

Vim testuwsgi.py

DEF application (env, Start_response):

Start_response (' K OK ', [(' Content-type ', ' text/html ')])

Return "Uwsgi ok!"

Command line execution:

Uwsgi--http:8001--wsgi-file testuwsgi.py

Browser test:127.0.0.1:8001

2. Configure site/wsgi.py

Import Sys

Import OS

Os.environ.setdefault ("Django_settings_module", "logsite.settings")

From Django.core.wsgi import get_wsgi_application

application = Get_wsgi_application ()

Sys.path.append ('/site ')

Sys.path.append ('/site/site ')

3. Test Uwsgi +django

Execute command:

uwsgi--http:8001--chdir/site/site--module wsgi

/site/site is the directory of wsgi.py

Wsgi as Module

Browser test: 127.0.0.1:8001

4. Nginx + Uwsgi + Django

4.1 Creating Nginx + UWSGI for socket connection XML file

Vim/site/uwsgi-socket.xml

<uwsgi>

<socket>:8001</socket> <!--do not use 8000 port, reserved 8000 convenient interpreter test--

<chdir>/Site/Site</chdir>

<module>wsgi</module>

<processes>4</processes><!--Process Number--

<daemonize>uwsgi.log</daemonize><!--Create a log file--

</uwsgi>

4.2 Modifying the nginx.conf configuration file

server {

listen 8080;

server_name www.site.com;

Access_log/logs/access.log;

Error_log/logs/error.log;

Location /{

Include Uwsgi_params;

Uwsgi_pass 127.0.0.1:8001;

Uwsgi_paramuwsgi_chdir/site/site;

Uwsgi_paramuwsgi_script Wsgi;

}

#静态文件路径

location/static {

alias/site/static;

}

}

4.3 Restart Nginx Service

Cd/usr/local/nginx/sbin

./nginx-s Reload

4.4 Starting the UWSGI server

Uwsgi-x Django-socket.xml

4.5 Access to services

ip:8080

Www.site.com

Nginx+uwsgi Deploying Django

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.