• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to run django with nginx

June 28, 2013 by Sharad Chhetri Leave a Comment

In this tutorial we will learn how to configure nginx with django project in Ubuntu 12.04 LTS .
Here in this scenario I have already putted the Django Project code in /opt and before this I installed django from its source code.

Actually in this scenario the code was developed in staging machine and I moved it to live server.In your case it may be in your own server

Project Directory Location : /opt/myproject
Python Version : Python 2.7
Django Version 1.5.1


Follow the given below steps to move your project code in new server or /opt in same server

Download the django and install it

wget https://www.djangoproject.com/m/releases/1.5/Django-1.5.1.tar.gz
tar -xzvf Django-1.5.1.tar.gz
cd Django-1.5.1
sudo python setup.py install


Now copy your project code to /opt
(Python modules you have to install as per your project requirement) I transfer my project code through scp into new server and copied it to /opt

cp -rvf /root/myproject /opt

Follow the given below steps to configure with nginx

Step 1: Install nginx and python flup

apt-get -y install nginx python-flup

Step 2: Create a file in /etc/nginx/sites-available with the name
myproject.conf

vi /etc/nginx/sites-available/myproject.conf


server {
    listen 80;
    server_name ubuntu.example.com;
    charset     utf-8;
    root   /opt/myproject/;
    access_log /var/log/nginx/ubuntu.example.com.access.log;
    error_log /var/log/nginx/ubuntu.example.com.error.log;
 
    location / {
        include fastcgi_params;
        fastcgi_pass ubuntu.example.com:8080;
         fastcgi_split_path_info ^()(.*)$;
    }
 
     location ~* .(ico|css|js|gif|jpe?g|png|svg|flv)(?[0-9]+)?$ {
     expires max;
     log_not_found off;
     }
}

Step 3: Create a symlink to enable the new site

 ln -s /etc/nginx/sites-available/myproject.conf /etc/nginx/sites-enabled/myproject.conf 

Step 4: Now run the fastcgi

Note: Python Version is 2.7

Here manage.py is main python file through which the project will run. Contact to your python developer and ask him to change the host url in file.

python /opt/myproject/manage.py runfcgi host=http://ubuntu.example.com port=8080

Step 5: Now restart the Nginx

 /etc/init.d/nginx restart 

Now open the web-browser and check the site.
in my scenario link was http://ubuntu.example.com

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework
  2. Can’t load ‘/usr/local/lib64/perl5/auto/nginx/nginx.so’
  3. How to install nginx webserver from source on CentOS and RHEL
  4. How to install nginx from source on CentOS 7
  5. Nginx : could not build the server_names_hash, you should increase server_names_hash_bucket_size
  6. Setup htpasswd on WordPress wp-admin running on nginx
  7. Configure Nginx for Jekyll / Octopress / pelican based static website
  8. Install Nginx from source code on Ubuntu 14.04 LTS
  9. Install and compile nginx 1.14 on Ubuntu 18.04 LTS server
  10. How To Install Nginx On Ubuntu 22.04 LTS

Filed Under: Linux, Server Tagged With: django, nginx

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Linux Commands

Force linux user to change password upon login

Install lxml by using pip command on Ubuntu 14.04 LTS

How to find installation date and time of rpm package

Jpeg Image Optimization / Compress on Linux

sed : find the pattern (keyword) and delete the line from file

Temporarily change the shell after login

How to print particular line number by using sed command

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

configure: error: C++ compiler cannot create executables

SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

GNU Screen

Keep logs of user after sudo su – : Secondary Logging

Install and optimize the png file by using optipng

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

How to change hostname in Ubuntu 12.04 and 12.10 without system restart

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Internal External Command

What is Linux/Unix Internal And External Command

Linux basic command

Linux Basic Commands For Every Beginner

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy