Python+nginx+gunicorn Deploying Django Notes

Source: Internet
Author: User
Tags install django pip install django server port

Deployment environment

    1. Ubuntu 12.04 LTS

    2. Django 1.6.2

    3. Nginx 1.1.19

    4. Guniron 19.3.0


Install configuration Items

  1. To install Django:

    Pip Install django==1.6.2

  2. Install Nginx, this step applies to Ubuntu:

    Apt-get Install nginx

    Other: Recommended source installation

    Nginx command:

    Start:/etc/init.d/nginx start

    Stop:/etc/init.d/nginx stop

    Test configuration file is correct: nginx-t

    Configure the Proxy function:

    1.1 Create the test file in the/etc/nginx/site-available/directory

    server {

    Listen 9600; Listen for the port number, which is the port number available on the server, or it will fail

    server_name localhost;

    server_name 127.0.0.1; This should be changed to a public IP address

    Access_log/opt/logs/nginx/wasp_ticket_stat.log;

    Error_log/opt/logs/nginx/wasp_ticket_stat_error.log;

    Location/{

    Proxy_pass http://127.0.0.1:9090; Fill in the server port that is forwarded to the Gunicorn binding

    Proxy_set_header Host $host;

    Proxy_set_header X-real-ip $http _x_real_ip;

    Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

    }

    }

  3. Install Gunicorn:

    Gunicorn (gunicorn.org) is a Python WSGI Unix http server. , from the Ruby Unicorn (Unicorn) project transplant. It is compatible with many different web frameworks and is easy to implement, lightweight, and responsive.

    Pip Insatll Gunicorn

    Once installed, you can create a Django project and a Django app .

    django-admin.py Startproject ProjectName
    Python manages.py Startapp AppName

Then CD appname,gunicorn appname.wsgi:application--bind 0.0.0.0:9090, 9090 ports bound on this machine

You can now view port occupancy with NETSTAT-LPNT

Then use Curl 127.0.0.1:9090 to test, if the following conditions, indicating success:

<! DOCTYPE html>

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">

<meta name= "Robots" content= "none,noarchive" ><title>welcome to Django</title>

<style type= "Text/css" >

HTML * {padding:0; margin:0;}

Body * {padding:10px 20px;}

Body * * {padding:0;}

body {Font:small Sans-serif;}

Body>div {border-bottom:1px solid #ddd;}

h1 {Font-weight:normal;}

h2 {Margin-bottom:.8em;}

H2 span {font-size:80%; color: #666; font-weight:normal;}

h3 {margin:1em 0.5em 0;}

h4 {margin:0 0.5em 0; Font-weight:normal; }

Table {border:1px solid #ccc; border-collapse:collapse; width:100%; background:white;}

Tbody td, Tbody th {vertical-align:top; padding:2px 3px;}

thead th {padding:1px 6px 1px 3px; background: #fefefe; text-align:left; font-weight:normal; font-size:11px; border:1px so Lid #ddd; }

tbody th {width:12em; text-align:right; color: #666; padding-right:.5em;}

#summary {background: #e0ebff;}

#summary h2 {font-weight:normal; color: #666;}

#explanation {background: #eee;}

#instructions {background: #f6f6f6;}

#summary table {border:none; background:transparent;}

</style>


<body>

<div id= "Summary" >

</div>


<div id= "Instructions" >

<p>

Of course, you haven ' t actually do any work yet.

Next, start your first app by running <code>python manage.py Startapp [Appname]</code>.

</p>

</div>


<div id= "Explanation" >

<p>

You ' re seeing the message because you have <code>debug = true</code> in your

Django settings file and you haven ' t configured any URLs. Get to work!

</p>

</div>

</body>


Restart Nginx:nginx-s Reload

Nginx Restart

Visit ip:9600 to


Python+nginx+gunicorn Deploying Django Notes

Related Article

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.