Saturday 28 January 2017

Setting up Django Project Production Ready

Deploy Django Application with PostgreSQL, Nginx, Gunicorn, Virtualenv and Supervisor

Deploy Django Application project for Production Environment

Deploy Django Application on Linux Machine

Video Tutorial



Django is a powerful python web framework build for rapid development. It takes care of much of problems of web development, so you can only focus on writing your app rather than reinventing the wheel. The most interesting thing about Django is that it is free and open source.

So lets begin with the deployment procedure for any Django based application. The recommended configuration for running a Django application is a bit complex. It includes tools like: PostgreSQL, Nginx, Gunicorn, Virtualenv, Supervisord. This are advanced tools that makes the Django application more efficient.

There are some prerequisites for this tutorial, you must be ready with:

  1. A Debian based Linux machine with sudo privileges.
  2. A domain name server that will point to your server's IP.

Lets start the deployment process.

1. First start with the updating packages that are already available on server. So that server will be up to date. For this:

$ sudo apt-get update
$ sudo apt-get upgrade

2. Now, install postgreSQL and its required package.

$ sudo apt-get install postgresql postgresql-contrib

Lets create a database user and database for our Django application. For this first login as a postgres user, as by default only this user has privileges to create database in postgreSQL.

$ sudo su - postgres

Now, you are logged in as postgres user. lets create database user and assign necessary privileges to it.

postgres@ubuntu:~$ createuser --interactive -P
Enter name of role to add: db_user
Enter password for new role: 
Enter it again: 
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n
postgres@ubuntu:~$

In above example, database user name is db_user. You can give the name as per your wish. Create database now. Give a appropraite name to database as well, as per your Django application.

postgres@ubuntu:~$ createdb --owner db_user django_db

here db_user is a databse user and django_db is a database name. Now logout from postgres user.

postgres@ubuntu:~$ logout
$

3. Till now our database setup is done. Now create a virtual environment for our Django application. For this we need to install, virtualenv package.

$ sudo apt-get install python-virtualenv

Now create a virtual environment.
Note: I am going to keep my django application in default folder that is /home/ubuntu/, So i will create my virtual environment here. If you want to keep your application in some other directory like /var/www/ then change your directory accordingly.

$ virtualenv -p python3 django_env

New python executable in django_env/bin/python
Installing distribute..............done.
Installing pip.....................done.

Here djano_env is the virtual environment name. Change it as per you, if required. To activate this environment, run

$ source django_env/bin/activate
(django_env) $

Now, install all the requirements of your project here, including django. Like:

(django_env) $ pip install django
Downloading/unpacking django
(...)
Installing collected packages: django
(...)
Successfully installed django
Cleaning up...

4. Now, clone your project directory, if you have already created project. Here I am creating a sample project for demo.

(django_env) $ django-admin.py startproject sample_project

Here project name is sample_project. Now check whether all your project requirement is setup or not by running it on development server. For this first navigate into your project and run the server.

(django_env) $ cd sample_project

(django_env) $ python manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found
Django version 1.10.1, using settings 'hello.settings'
Jan 09, 2017 - 06:12:00
Development server is running at 0.0.0.0:8000/
Quit the server with CONTROL-C.

Our project is running on Server's public IP with port 8000. Now quit the server by pressing CONTROL-C.

5. Now, we need to configure postgreSQL so that it can communicate with our Django application. For this, install psycopg2 database adapter. But this adapter have some package dependencies, so first install them.

(django_env) $ sudo apt-get install libpq-dev python3-dev

Now install,

(django_env) $ pip install psycopg2

Now, configure database section in your project's settings.py file.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django_db',
        'USER': 'db_user',
        'PASSWORD': '<password you entered when creating db_user>',
        'HOST': 'localhost',
        'PORT': '',                      # Set to empty string for default.
    }
}

Also add, your server's IP or domain name in settings.py as follow:

ALLOWED_HOSTS = ['<your server's IP or domain name>']

Without above setting, Django will not be accessible from your domain name or IP address. This is the security feature of Django.

Now, synchronise the database

(django_env) $ python manage.py migrate

Now our database setup is fully done.

6. Now we will setup our app server that is Gunicorn rather than using Django's by default single threaded development server.

(django_env) $ pip install gunicorn
Downloading/unpacking gunicorn
  Downloading gunicorn-0.17.4.tar.gz (372Kb): 372Kb downloaded
  Running setup.py egg_info for package gunicorn
Installing collected packages: gunicorn
  Running setup.py install for gunicorn
    Installing gunicorn_paster script to /webapps/hello_django/bin
    Installing gunicorn script to /webapps/hello_django/bin
Successfully installed gunicorn
    Installing gunicorn_django script to /webapps/hello_django/bin
Cleaning up...

Now you have gunicorn working, test it by running

(django_env) $ gunicorn sample_project.wsgi:application --bind 0.0.0.0:8001

Now, you can access gunicorn from your server's public IP with port 8001. Now to make gunicorn more useful for our django application, we need to configure its option. For this make a bash script called gunicorn.bash. You can change file name as per your choice.

(django_env) $ vim gunicorn_start.bash

now add following configurations into file

#!/bin/bash

NAME="django_app"                                   # Name of the application
DJANGODIR=/home/ubuntu/sample_project               # Django project directory
SOCKFILE=/home/ubuntu/django_env/run/gunicorn.sock  # we will communicte using this unix socket
USER=ubuntu                                         # the user to run as
GROUP=ubuntu                                        # the group to run as
NUM_WORKERS=3                                       # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=sample_project.settings      # which settings file should Django use
DJANGO_WSGI_MODULE=sample_project.wsgi              # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the virtual environment

cd $DJANGODIR
source /home/ubuntu/django_env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist

RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

Here, all the variables are well explained in their comment part respectively. Change the variables value according to your configuration. Like NAME variable will define how you application will be identified in programs like ps, top etc. The recommended way to define no of workers is equals to 2*CPUs+1. For example, for a single CPU machine should be set with 3 workers.

Now make this script executable.

$ sudo chmod u+x gunicorn_start.bash

Lets test this script by running it.

(django_env) $ ./gunicorn_start.bash
Starting hello_app as hello
2013-06-09 14:21:45 [10724] [INFO] Starting gunicorn 18.0
2013-06-09 14:21:45 [10724] [DEBUG] Arbiter booted
2013-06-09 14:21:45 [10724] [INFO] Listening at: unix:/webapps/hello_django/run/gunicorn.sock (10724)
2013-06-09 14:21:45 [10724] [INFO] Using worker: sync
2013-06-09 14:21:45 [10735] [INFO] Booting worker with pid: 10735
2013-06-09 14:21:45 [10736] [INFO] Booting worker with pid: 10736
2013-06-09 14:21:45 [10737] [INFO] Booting worker with pid: 10737
^C (CONTROL-C to kill Gunicorn)

2013-06-09 14:21:48 [10736] [INFO] Worker exiting (pid: 10736)
2013-06-09 14:21:48 [10735] [INFO] Worker exiting (pid: 10735)
2013-06-09 14:21:48 [10724] [INFO] Handling signal: int
2013-06-09 14:21:48 [10737] [INFO] Worker exiting (pid: 10737)
2013-06-09 14:21:48 [10724] [INFO] Shutting down: Master
$ exit

7. Now, its time to setup supervisor so that it can supervise our application. If system reboots or application quits unexpectedly, supervisor will take care of its restart. For this, first install it.

$ sudo apt-get install supervisor

To supervise any program through supervisor, you need to create configuration file for that program inside /etc/supervisor/conf.d/ directory. For our Django application that is sample_project, we will create sample_project.conf

$ sudo vim /etc/supervisor/conf.d/sample_project.conf

Now, write following content into the opened file.

[program:sample_project]
command = /home/ubuntu/gunicorn_start.bash                  ; Command to start app
user = ubuntu                                                ; User to run as
stdout_logfile = /home/ubuntu/logs/gunicorn_supervisor.log   ; Where to write log messages
redirect_stderr = true                                       ; Save stderr in the same log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8              ; Set UTF-8 as default encoding

Change the above configuration value according to your setup. As we mentioned in above file that the logs will be stored at /home/ubuntu/logs/gunicorn_supervisor.log, we need to make this directory and file.

(django_env) $ mkdir -p /home/ubuntu/logs/
(django_env) $ touch /home/ubuntu/logs/gunicorn_supervisor.log

After this done, we will ask supervisor to reread configuration files and update it so the our newly configuration file get add.

For Ubuntu 14.04:

$ sudo supervisorctl reread
sample_project: available

$ sudo supervisorctl update
sample_project: added process group

As you can see, our sample_project configuration file get added to supervisor process group. Now, start our app through it. For this

$ sudo supervisorctl start sample_project
sample_project: started

For Ubuntu 16.04:

$ sudo systemctl restart supervisor
$ sudo systemctl enable supervisor

To check status:

$ sudo supervisorctl status sample_project
sample_project                   RUNNING  pid 24768, uptime 0:00:10

To stop:

$ sudo supervisorctl stop sample_project
sample_project: stopped


To restart:

$ sudo supervisorctl restart sample_project
sample_project: stopped
sample_project: started

Now, our application will get automatically restart after system gets boot up or our application gets crashed.

8. Now, we need to setup last thing that is Nginx. So lets get start. Nginx will act as a server for our application. So first install it.

$ sudo apt-get install nginx

Now, we will need to create configuration file for our application inside /etc/nginx/sites-available/ directory. After this we will need to create symbolic link for it, in the /etc/nginx/sites-enabled directory. Lets do it one by one. First create configuration file.

$ sudo vim /etc/nginx/sites-available/sample_project.conf

Now, put following content into the opened file.

upstream sample_project_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).
  server unix:/home/ubuntu/django_env/run/gunicorn.sock fail_timeout=0;
}

server {

    listen   80;
    server_name <your domain name>;

    client_max_body_size 4G;
    access_log /home/ubuntu/logs/nginx-access.log;
    error_log /home/ubuntu/logs/nginx-error.log;

    location /static/ {
        alias   /home/ubuntu/static/;
    }

    location /media/ {
        alias   /home/ubuntu/media/;
    }

    location / {

        # an HTTP header important enough to have its own Wikipedia entry:
        #   http://en.wikipedia.org/wiki/X-Forwarded-For
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


        # enable this if and only if you use HTTPS, this helps Rack
        # set the proper protocol for doing redirects:
        # proxy_set_header X-Forwarded-Proto https;

        # pass the Host: header from the client right along so redirects
        # can be set properly within the Rack application
        proxy_set_header Host $http_host;

        # we don't want nginx trying to do something clever with
        # redirects, we set the Host: header above already.
        proxy_redirect off;

        # set "proxy_buffering off" *only* for Rainbows! when doing
        # Comet/long-poll stuff.  It's also safe to set if you're
        # using only serving fast clients with Unicorn + nginx.
        # Otherwise you _want_ nginx to buffer responses to slow
        # clients, really.
        # proxy_buffering off;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://sample_project_server;
            break;
        }
    }

    # Error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
        root /home/ubuntu/static/;
    }
}

Change the configuration value according to your setup. Now create the symbolic link for it.

$ sudo ln -s /etc/nginx/sites-available/sample_project.conf /etc/nginx/sites-enabled/sample_project.conf

Now, start the Nginx.

$ sudo service nginx start

Now, if you browse your server's domain name into browser, you will get your site running. Congrats, your production ready django application is set. :)

135 comments:

  1. When i am running the command $ supervisorctl restart sample_project


    its giving me error http://localhost:9001 refused connection

    I am not getting whats wrong with this

    ReplyDelete
  2. Hello Saurabh,

    This error basically arises when the specified port is not open or being used by some other process. Try to check it by issuing following command:
    sudo netstat -nltp

    This command will show on which port, which process is running. If the port is free then try to check status of your app that whether it is running or not. You can check it with:
    sudo supervisorctl status sample_project

    If it is showing, "running" then try to check, log file which is stored in ~/logs/gunicorn_supervisor.log, it will tell you why it is happening.
    For more insights about the whole procedure, you can use video tutorial as well!
    Let us know, if your problem still persist after applying above solutions.

    ReplyDelete
  3. Gunicorn Permission Denied error while running the bash script.

    ReplyDelete
    Replies
    1. Hey, you probably have not given appropriate permission to file. Run following command mentioned in post:
      sudo chmod u+x gunicorn_start.bash

      Still, if you are getting same error then run:
      sudo chmod ugo+x gunicorn_start.bash

      This will solve your error. Let us know, if problem still persist.

      Delete
    2. still not working after applying above commands...my ubuntu user is mahesh and group is set to www-data..

      But if i remove user and group it works fine.

      Delete
    3. Try to run following command:
      sudo chown mahesh gunicorn_start.bash
      then:
      sudo chmod ugo+x gunicorn_start.bash

      It should solve your problem.

      Delete
  4. Application not running... showing this error in NGINX Logs.

    2017/04/04 13:07:25 [error] 2850#2850: *1 connect() failed (111: Connection refused) while connecting to upstream..

    How to solve this error.

    ReplyDelete
    Replies
    1. Complete Error in Log:

      2017/04/04 13:19:30 [crit] 3121#3121: *1 connect() to unix:/home/ubuntu/django/djangoenvironment/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.100, server: <your, request: "GET / / HTTP/1.1", upstream: "http://unix:/home/ubuntu/django/djangoenvironment/run/gunicorn.sock:/"

      Delete
    2. Can you please give me the output of "/home/ubuntu/logs/gunicorn_supervisor.log"?

      Delete
    3. Thanks the problem has been solved..I forgot to restart the supervisor after making some changes.

      Delete
    4. Nice! Thanks for using this post. Keep learning, keep sharing.

      Delete
  5. I have a problem with supervisor: 404

    (env) root@vz281558:~# systemctl start supervisor
    (env) root@vz281558:~# supervisorctl tail -f sample_project
    ==> Press Ctrl-C to exit <==
    unix:///var/run/supervisor.sock/logtail/sample_project/stdout Cannot read, status code 404


    My files:

    /etc/supervisor/conf.d/sample_project.conf

    [program:sample_project]
    command=/home/env/bin/gunicorn_start
    user=root
    stdout_logfile=/home/env/logs/gunicorn_supervisor.log
    redirect_stderr=true
    environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8


    /home/env/bin/gunicorn_start (I made this file as executable: chmod u+x gunicorn_start)

    #!/bin/bash

    NAME="myproject"

    DJANGODIR=/home/env/myproject/

    SOCKFILE=/home/env/myproject/run/gunicorn.sock

    USER=root
    GROUP=root
    NUM_WORKERS=3

    DJANGO_SETTINGS_MODULE=myproject.settings
    DJANGO_WSGI_MODULE=myproject.wsgi

    echo "Starting $NAME as `whoami`"

    cd $DJANGODIR
    source ../bin/activate
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH

    RUNDIR=$(dirname $SOCKFILE)
    test -d $RUNDIR || mkdir -p $RUNDIR

    exec /home/env/bin/gunicorn ${DJANGO_WSGI_MODULE}:application --name $NAME --workers $NUM_WORKERS --user=$USER --group=$GROUP --bind=unix:$SOCKFILE --log-level=debug --log-file=-


    But when I run gunicorn_start directly: ./gunicorn_start I'm getting this:
    https://pastebin.com/embed_iframe/FUb83yMd

    Could you help me ?

    ReplyDelete
    Replies
    1. Its look like that your `gunicorn_start` script is running fine. I wonder why you are running command `supervisorctl tail -f sample_project`.
      Can you please provide the output of the file `/home/env/logs/gunicorn_supervisor.log`, It will help me look into your supervisor related issue.

      Also try to run:
      systemctl restart supervisor

      then:
      supervisorctl status sample_project

      And let me know the what it gives the output.

      Delete
    2. PROBLEM SOLVED !!!
      THANK YOU SO MUCH FOR THIS TUTORIAL !!! <3

      Delete
  6. Thanks for tut. But I was not able to load static files even after nginx config.

    ReplyDelete
    Replies
    1. Same problem here.....

      Delete
    2. Same problem... Did anyone figure it out?

      Delete
  7. work perfect nice step by step explanation :)

    ReplyDelete
  8. If I don't have server_name, what I have to put into /etc/nginx/sites-available/sample_project.conf??

    ReplyDelete
  9. Hello. Thank you for the tutorial. I'm having a problem with the gunicorn_start.bash file tho. It just prints Starting as jonas
    usage: gunicorn [OPTIONS] [APP_MODULE]
    gunicorn: error: argument -n/--name: expected one argument

    and does not work. Ḯ've tried to ask google, but nothing seems to help. Am i supposed to change the 'whoami' part?

    ReplyDelete
  10. Woah... Thank you very much... best simplified and easy tutorial to follow.. I got it all working after battling with tutorials from linode and digitalocean among many others without success all throughout yesterday .. You rock

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I've got thos error in error.log of nginx : "2017/07/19 15:58:49 [emerg] 28550#0: host not found in upstream "www.mysite.com" in /etc/nginx/sites-enabled/mysite.conf:54" and this line refers to proxy_pass http://mysite.com; PLEASE HELP

    ReplyDelete
    Replies
    1. Hey, you are doing something wrong, as we are not referring www.mysite.com anywhere in the Nginx config. Just recheck your configuration file

      Delete
    2. is the proxy_pass correct ?

      Delete
    3. Yup. The Syntax is correct. But in tutorial, we are using socket file to connect with Application server that is Gunicorn.

      Delete
  13. I followed your tutoriel using my django application that i want to deploy, and i get an "400 Bad Request
    Request Header Or Cookie Too Large" any idea ? i tried many things but none worked

    ReplyDelete
    Replies
    1. Have you added, your IP address (or localhost address, if you are trying locally) in `ALLOWED_HOSTS` settings in Django settings file of your project as follow?
      ALLOWED_HOSTS= ['']

      Delete
    2. I did add my domain name as follow : ALLOWED_HOSTS= ['.name.com', 'www.name.com']

      Delete
    3. Replace .name.com with name.com and which domain you are using to access the Django application?

      Delete
  14. A great guide. I build my production server using your notes. Thx!
    One question. According to your instructions, after I tune gunicorn bash script and run it: gunicorn automaticaly creates socket with 777 permissions and under "ubuntu" user, which is owner of project folder. In same time usually nginx starts as www-data, so when nginx try to read from socket, he get permission from last 7 (All others). Many will say, such a wide permissions, not the best solution for production. Please tell me are there any opportunity to downgrade socket permisions from gunicorn (for example 660), so everything will stil work

    ReplyDelete
    Replies
    1. Hello Tk,
      By default, gunicorn creates socket file with 777 permission. We can only control user and group permission. You can use `--bind` option, so that socket will be available only from the bind values.
      Foe example:
      --bind unix:$SOCKFILE
      OR
      --bind 127.0.0.1:8000

      I hope, it will be useful for you.

      Delete
    2. I'm appreciated for your help!
      What did you mean when you write "use `--bind` option, so that socket will be available ONLY from the bind values"? (???ONLY???)

      Delete
    3. Hey Tk,

      What i have mentioned is explained in official document of Gunicorn in detail here:
      http://docs.gunicorn.org/en/stable/settings.html#bind

      Delete
  15. I got through most of this tutorial and I know I'm very close. I tested gunicorn in the command line and it worked there. When I run '$ sudo supervisorctl start sample_project' I get an ERROR (spawn error). When I run 'sudo supervisorctl status sample_project' it returned FATAL Exited too quickly. The gunicorn_supervisor.log file contains this:
    EACCES
    supervisor: child process was not spawned.

    Any help is greatly appreciated!

    ReplyDelete
    Replies
    1. Does following command works fine?

      `./gunicorn_start.bash`

      Delete
    2. It was running into an error on line 27 saying command source not found. I had to modify the beginning of line 2 of sample_project.conf to 'command=bash ' to get the issue to disappear. I currently have nginx running but when I go to my domain i get a 404 not found when I expect to see my index page. Thanks for your help!

      Delete
    3. This comment has been removed by the author.

      Delete
    4. Hello Lior, when you run `./gunicorn_start.bash` , what error it throws? Can you please provide the output?

      Delete
  16. Awesome blog and video. Thanks a ton.

    Cheers!!

    ReplyDelete
    Replies
    1. Thanks mate. Like and subscribe on YouTube to get regular updates from us.

      Delete
  17. After all setup , i am getting Nginx home page not the project home page .Please help.

    ReplyDelete
    Replies
    1. Follow this exact tutorial of above and see if you are missing something
      https://www.youtube.com/watch?v=jN9iPaQzZbQ

      Delete
  18. Hey hey hey hey! Your tutorial is awesome!

    However, I got this 403 Forbidden error page. My nginx-error log says permission is denied for gunicorn.sock

    Error message:
    connect() to unix:/root/akhil_env/run/gunicorn.sock failed (13: Permission denied) while connecting to upstream

    Can you please help me? I ran chmod u+x and ugo+x on gunicorn bash file. Didn't work. My user is 'root' and group is also 'root' and my django app is in /root/akhil_env/ directory. My supervisor log says three workers are running with process ids. So where is the problem? I tried restarting supervisor and the status showed running.

    ReplyDelete
    Replies
    1. HEY!!!!! Thank you!!!! I got it! I made a mistake by cloning my project into /root/ directory. I changed it to /home/ and it worked! I'm so happy! Thank you very much!

      Delete
    2. Hello Akhil
      Thanks for your appreciation, I will recommend to create a user specific for your project and do all the stuff using that user only. Like I use ubuntu user (that comes by default with Ubuntu distribution of Linux). If you need any help on, how to create user then, check this video tutorial https://www.youtube.com/watch?v=zd1MdEwuPY4

      Delete
  19. really nice article. clarified most of my doubts.

    ReplyDelete
  20. Hi.
    I have a doubt. If I had to deploy two django applications simultaneously, then what are the basic things I need to do/change? for example, I want one django app running at one.example.com and another at two.example.com. Can I do it?

    ReplyDelete
  21. Hello Akhil,

    For running two Django application following steps will be required:
    1. You need to create two databases and users (optional) if both the application uses different database
    2. Two separate virtual environment, will be required, to avoid python package conflicts
    3. Setup the code and settings file accordingly
    4. Two separate scripts of Gunicorn with respect to the application
    5. Two separate supervisor configuration with respect to the application , so that you can manage them accordingly
    6. Two separate configuration file of Nginx, for better management. You can provide respective DNS name inside the server_name entry.

    Thats all you need to do.

    ReplyDelete
    Replies
    1. Thank you very much ma'am, that looks simple. Will do that.

      Delete
  22. This comment has been removed by the author.

    ReplyDelete
  23. Hi, Nicely explained.
    But stuck with one (don't know simple of big) problem.
    I am using linux vps. i have vesta cp installed in my system. To manage my server. So i don't know it has any side effect on my process or what.
    I tried everything working just perfect . I tired

    gunicorn DjangoBeginnersGuide.wsgi:application --bind 0.0.0.0:8001
    python manage.py runserver
    sudo supervisorctl status boards
    sudo service nginx restart.

    Each command work just fine but still i can't see my site in my requested domain(live not localhost) . Also there has no chance for the domain to not work. As i am running other subdomains in this server as well. Also my this domain is showing the default page of my server.

    ReplyDelete
  24. But i checked
    access_log /home/boards/logs/nginx-access.log;
    error_log /home/boards/logs/nginx-error.log;
    thse 2 file haven't been created.

    ReplyDelete
  25. Hi Salman, Try to delete default configuration file of Nginx, available in /etc/nginx/sites-available/ directory, then restart the Nginx service. Same steps are mentioned in above linked video.
    I hope it will help!

    ReplyDelete
  26. Hi thanks for you quick reply.
    I don't have any default configure file there.only my own conf file is there.
    But as i said i have installed vesta cp in my server so i got one nginx.conf file in my
    /home/admin/conf/web directory . There i have one apache2.conf and one nginx.conf file.

    ReplyDelete
  27. ahh. It worked for me now. The problem was apache2 and nginx was conflicting. I remove vesta VP now working great.

    ReplyDelete
  28. This comment has been removed by the author.

    ReplyDelete
  29. Hi, following your suggestion to run django app on a subpath, I'm using gunicorn and nginx but not supervisor, I created the following NGINX server with no luck:

    server {
    listen 80;
    server_name www.officinecartografiche.it, officinecartografiche.it, 207.154.206.172;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
    root /home/geouser/pmapp;
    }

    location /pmapp {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    if (!-f $request_filename) {
    proxy_pass http://unix:/home/geouser/pmapp/pmapp.sock;
    proxy_set_header SCRIPT_NAME /pmapp;
    break;
    }
    }
    }

    ReplyDelete
  30. Interesting read! Thank you for the well & detailed explanation on Setting up Django Project Production. Keep posting.

    ReplyDelete
  31. I think it's a very helpful tutorial for django deployment.
    When i try to execute :
    $ sudo systemctl restart supervisor
    $ sudo systemctl enable supervisor

    $ sudo supervisorctl status sample_project

    Result : unix:///var/run/supervisor.sock no such file
    But i am not understood where is the problem :(

    ReplyDelete
  32. Looks like supervisor daemon is not up and running. Run below command to check the same:
    sudo service supervisor status

    if it is not running then start it with following command:
    sudo service supervisor start

    ReplyDelete
  33. Great tutorial. Best tutorial so far for django deployment
    I got a problem.


    I did not encounter any of the errors that others have encountered (I guess) Everything works fine except when I visit my mezzanine (django-based cms) app.

    this my app: https://35.197.54.139

    It seems like my app is not mapped to the IP address I've given because it just says, "Safari can't connect to the server". That one is my VM instance's external IP address.

    I am using google compute engine Virtual Machine.

    Please help.

    ReplyDelete
    Replies
    1. Hello Rejeenald Flores!

      Thanks a ton for your kind words. Just wondering whether you configured SSL certificate in Nginx or not, as you are using https protocol. SSL certificate configuration is not covered on this tutorial.

      I surfed your public IP over http protocol that is `http://35.197.54.139/`. Looks like Nginx is up and running. Its giving `404 Not Found` error. So please check routes of your application.

      Delete
    2. Hi, thank you for your response. :) Is it okay if I ask where is a good start to the SSL Certificate configuration in google cloud platform? I know this is not covered in the tutorial, but your suggestion will be a great help for me too. Also, what do you mean about checking routes of my application? Sorry I'm a newbie.

      Delete
    3. Use below link to apply SSL certificate on Nginx:
      http://jee-appy.blogspot.com/2017/12/apply-ssl-certificate-nginx.html

      And routes means, the path we configure in "views.py" file in our project.

      Delete
    4. Do I need to do SSL certification because I think I already have an SSL certificate. I am using google cloud compute engine virtual machine instance running on Debian.

      Delete
  34. hey dude i got an error while start supervisor

    error log says :

    supervisor: couldn't exec /home/ubuntu/gunicorn_start.bash: EACCES
    supervisor: child process was not spawned



    kindly help me

    ReplyDelete
    Replies
    1. Hi Sathis,

      Check whether your `/home/ubuntu/gunicorn_start.bash` file is executable or not by supervisor. It looks like permission error.

      Delete
    2. it was executable

      i run ./gunicorn_start.bash succesfully

      Delete
    3. Provide output of command `/home/ubuntu/gunicorn_start.bash` and also provide logs of supervisor.

      Delete
    4. (django_env)root@ip-172-31-31-246:/home/ubuntu# sudo supervisorctl start cymune
      cymune: ERROR (abnormal termination)
      (django_env)root@ip-172-31-31-246:/home/ubuntu#




      output for : ./gunicorn_start.bash

      [2017-12-15 14:29:55 +0000] [9281] [INFO] Starting gunicorn 19.7.1
      [2017-12-15 14:29:55 +0000] [9281] [DEBUG] Arbiter booted
      [2017-12-15 14:29:55 +0000] [9281] [INFO] Listening at: unix:/home/ubuntu/django_env/run/gunicorn.sock (9281)
      [2017-12-15 14:29:55 +0000] [9281] [INFO] Using worker: sync
      [2017-12-15 14:29:55 +0000] [9290] [INFO] Booting worker with pid: 9290
      [2017-12-15 14:29:55 +0000] [9291] [INFO] Booting worker with pid: 9291
      [2017-12-15 14:29:55 +0000] [9281] [DEBUG] 3 workers
      [2017-12-15 14:29:55 +0000] [9292] [INFO] Booting worker with pid: 9292

      Delete
    5. error log

      /home/ubuntu/gunicorn_start.bash: 28: exec: gunicorn: not found
      Starting cymune as ubuntu

      Delete
  35. This comment has been removed by the author.

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. How to create a production ready code build test deploy pipeline using Django and Jenkins.

    ReplyDelete
  38. There is a situation in Django project where we are using Celery and Redis or RabbitMQ for processing background tasks and what happens when the process gets failed to start.

    For this kind of situation we will introduce Supervisor but what will happen if celery is unable to connect to redis host and the entire application will halt down.

    How can we bypass this problem if celery fails to connect to one of its broker either(redis or rabbitmq).

    ReplyDelete
  39. Hi Rohini, this tutorial is awesome. Thank you so much. But I got an error message though - when I ran/tested the supervisor: "FATAL Exited too quickly (process log may have details)". I have read other comments about this but haven't found any concrete solutions yet. You might want to enlighten us regarding this particular issue. Thanks again and looking forward for your new tutorial.

    ReplyDelete
  40. Hello,
    Great tutorial.

    I have done all the steps, but still I'm getting 403 error.
    Things were working till "gunicorn sample_project.wsgi:application --bind 0.0.0.0:8001" this command and that something messed up.

    I am using DigitalOcean - Ubuntu 16
    I am a root user and my project's name is 'ecommerce' which is in /root/src (This dir contains manage.py)
    my env is the same as yours but is in /root/django_env

    I think it's the permissions, but I am not sure.
    Can you please help me out?

    Thank you so much.

    ReplyDelete
  41. Hi Rohini, First of all very much thankful to you for very nice tutorial.

    I have completed all the steps as mentioned.But, I'm getting the error "404 NOT FOUND" when I try to open 192.168.1.10 in the browser( This is the IP of my UBUNTU PC and the same is given at ALLOWED HOSTS).

    I am suspecting supervisor may be malfunctioning. when the status is seen some times showing "running", immediately it is showing "starting".

    the status of supervisor is as follows.

    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3198, uptime 0:00:05
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3210, uptime 0:00:05
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project STARTING
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3253, uptime 0:00:05
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project STARTING
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3261, uptime 0:00:02
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3261, uptime 0:00:03
    (django_env) root@sdesalestrp-Veriton-M2120G:/home/ubuntu# sudo supervisorctl status sample_project
    sample_project RUNNING pid 3274, uptime 0:00:02

    please help to solve the problem

    THank you so much

    ReplyDelete
  42. This tutorial is just awesome, I tried to deploy my django app by following several tutorials, and this is the first that actually works for me. Also I don't just "followed it", I really understood it, and the replys to the comments were very useful too. Thanks!!!

    ReplyDelete
    Replies
    1. Thanks for your appreciation. Please like the video for this tutorial and subscribe the channel #Appychip on youtube - https://www.youtube.com/watch?v=jN9iPaQzZbQ
      Please keep us motivated by subscribing

      Delete
  43. This has helped me so much, thank you!!

    ReplyDelete
  44. First off, I want to say Thank you so much for this tutorial. It was very helpful. I've got my site up and running, but for some reason it isn't loading my static files. I changed the settings for /etc/nginx/sites-available/sample_project.conf with the location of my static folder in the project file, but it still isn't loading them. Any ideas on what's going on? Thanks again for this amazing tutorial!

    ReplyDelete
  45. Why i am getting ?

    to unix:/home/deploy/django_env/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream

    ReplyDelete
    Replies
    1. Check if /home/deploy/django_env/run/gunicorn.sock file is present or not on this path. If its using some other path then update it accordingly.

      Delete
  46. Thanks for quick response, I found that when i was running nginx, it was not communicating with gunicorn,
    So i restarted supervisor and gunicorn than after nginx is working properly.

    ReplyDelete
    Replies
    1. Great! Just in case if you are missing anything, you can refer the video tutorial demonstrating the steps shown in this post on our youtube channel - https://www.youtube.com/watch?v=jN9iPaQzZbQ
      Please like and subscribe our channel to keep us motivated.
      keep Learning & Keep Sharing :)

      Delete
  47. when i am trying this command: supervisorctl status onlinetest
    i will get error like: unix:///var/run/supervisor.sock no such file What this error will come.

    I have install supervisor successfully.
    Please help me.
    Thanks in advance

    ReplyDelete
  48. When i am uploading sqlite-3 on digital ocean and update the database
    the database automatically delete the data which is inside the database
    in few minutes (approximate 5 min)
    how should i solve it thanx in advance

    ReplyDelete
  49. I followed each step successfully. The last step, I went back to the website domain and the Nginx information appeared correctly. Then I restarted the server in the virtual environment:

    (dev_env) kap@server:~/website$ sudo python3 manage.py runserver XXX.XXX.XXX.XXX:80

    with the following error:
    ---------------------------
    Traceback (most recent call last):
    File "manage.py", line 8, in
    from django.core.management import execute_from_command_line
    ModuleNotFoundError: No module named 'django'

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "manage.py", line 14, in
    ) from exc
    ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

    --------------------------
    Please advise

    ReplyDelete
  50. When i execute the command "./gunicorn_start.bash" it's showing that "No user 'ubuntu'". Can anyone help me

    ReplyDelete
    Replies
    1. Try exchanging 'ubuntu' with your user name (as seen in the terminal prompt... name@machine_name: )

      Delete
  51. I followed all the above step for deployment, but still I'm getting error so I posted that error in stack overflow. Could anyone help me to resolve this problem please.

    https://stackoverflow.com/questions/51025693/djanog-nginx-and-gunicorn-sock-failed-2-no-such-file-or-directory-while-con

    ReplyDelete
  52. Thank you!!! Just what I was looking for.

    ReplyDelete
  53. hello i have the same probleme as LIOR SHAHVERDI
    I tested gunicorn in the command line and it worked there. When I run '$ sudo supervisorctl start sample_project' I get an ERROR (spawn error). When I run 'sudo supervisorctl status sample_project' it returned FATAL Exited too quickly. The gunicorn_supervisor.log file contains this:
    EACCES
    did anyone solve it?
    Any help is appreciated!

    ReplyDelete
    Replies
    1. If you are from India change US to IN in last line of
      /etc/supervisor/conf.d/sample_project.conf file.. and then restart all stuffs..

      Delete
  54. I have doubt in output of 'gunicorn_start.bash file'. In file you have binded it with '/home/ubuntu/django_env/run/gunicorn.sock' but in output it is showing 'webapps/hello...' How?

    ReplyDelete
  55. Hi! I followed your nice tutoriel but when i run "supervisorctl status blockchain" i have the error: FATAL Exited too quickly (process log may have details).

    ReplyDelete
  56. Could you tell me Security Group settings because when I start ngnix it showed me welcome page but when I restarted it, This site can’t be reached, why?

    ReplyDelete
  57. hello Sir/madam
    i Stuck at here can you help me

    ./gunicorn_start.bash: line 14: /home/deploy/django_env/bin/activate: No such file or directory
    [2018-09-03 12:01:50 +0530] [7927] [DEBUG] Current configuration:

    [2018-09-03 12:03:25 +0530] [7937] [INFO] Starting gunicorn 19.9.0
    [2018-09-03 12:03:25 +0530] [7937] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
    [2018-09-03 12:03:25 +0530] [7937] [ERROR] Retrying in 1 second.
    [2018-09-03 12:03:26 +0530] [7937] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
    [2018-09-03 12:03:26 +0530] [7937] [ERROR] Retrying in 1 second.
    [2018-09-03 12:03:27 +0530] [7937] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
    [2018-09-03 12:03:27 +0530] [7937] [ERROR] Retrying in 1 second.
    [2018-09-03 12:03:28 +0530] [7937] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
    [2018-09-03 12:03:28 +0530] [7937] [ERROR] Retrying in 1 second.
    [2018-09-03 12:03:29 +0530] [7937] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
    [2018-09-03 12:03:29 +0530] [7937] [ERROR] Retrying in 1 second.
    [2018-09-03 12:03:30 +0530] [7937] [ERROR] Can't connect to /home/deploy/django_env/run/gunicorn.sock

    ReplyDelete
    Replies
    1. i also tried this command
      sudo chmod ugo+x gunicorn_start.bash
      but still getting error
      another thing i have no socket file created in the bin directory there is a file gunicorn not gunicorn.sock

      Delete
  58. Error showing: /home/deploy/django_env/bin/activate: No such file or directory

    Virtual environment not setup properly OR you are on wrong env path.

    ReplyDelete
    Replies
    1. raw_paste_global_conf: []
      [2018-09-04 11:13:09 +0530] [3603] [INFO] Starting gunicorn 19.9.0
      [2018-09-04 11:13:09 +0530] [3603] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
      [2018-09-04 11:13:09 +0530] [3603] [ERROR] Retrying in 1 second.
      [2018-09-04 11:13:10 +0530] [3603] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
      [2018-09-04 11:13:10 +0530] [3603] [ERROR] Retrying in 1 second.
      [2018-09-04 11:13:11 +0530] [3603] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
      [2018-09-04 11:13:11 +0530] [3603] [ERROR] Retrying in 1 second.
      [2018-09-04 11:13:12 +0530] [3603] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
      [2018-09-04 11:13:12 +0530] [3603] [ERROR] Retrying in 1 second.
      [2018-09-04 11:13:13 +0530] [3603] [DEBUG] connection to /home/deploy/django_env/run/gunicorn.sock failed: [Errno 13] Permission denied
      [2018-09-04 11:13:13 +0530] [3603] [ERROR] Retrying in 1 second.
      [2018-09-04 11:13:14 +0530] [3603] [ERROR] Can't connect to /home/deploy/django_env/run/gunicorn.sock
      any help here?

      Delete
  59. can you help me

    ModuleNotFoundError: No module named 'mysite'
    [2018-09-05 20:06:29 +0530] [22989] [INFO] Worker exiting (pid: 22989)
    [2018-09-05 20:06:29 +0530] [22990] [ERROR] Exception in worker process
    Traceback (most recent call last):
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
    File "/home/farman/my-first-blog/appvenv/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
    ModuleNotFoundError: No module named 'mysite'
    GROUP=www-data # the group to run as
    NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
    DJANGO_SETTINGS_MODULE=mysite.settings # which settings file should Django use
    DJANGO_WSGI_MODULE=mysite.wsgi # WSGI module name
    echo "Starting $NAME as `whoami`"

    # Activate the virtual environment

    cd $DJANGODIR
    source /home/farman/my-first-blog/appvenv/bin/activate
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH

    # Create the run directory if it doesn't exist

    RUNDIR=$(dirname $SOCKFILE)
    test -d $RUNDIR || mkdir -p $RUNDIR

    # Start your Django Unicorn
    # Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

    exec gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --workers $NUM_WORKERS \
    --user=$USER --group=$GROUP \
    --bind=unix:$SOCKFILE \
    --log-level=debug \
    --log-file=-

    ReplyDelete
  60. Configure the router settings using default 192.168.1.254 ip

    ReplyDelete
  61. I have this error when i execute ./gunicorn_start.bash


    [2018-10-02 19:34:23 +0100] [26632] [DEBUG] Current configuration:
    chdir: /home/ubuntu/django_env/gaalgui20
    umask: 0
    forwarded_allow_ips: ['127.0.0.1']
    proxy_allow_ips: ['127.0.0.1']
    max_requests: 0
    worker_int:
    post_request:
    do_handshake_on_connect: False
    child_exit:
    on_exit:
    raw_env: []
    accesslog: None
    errorlog: -
    logconfig_dict: {}
    syslog_prefix: None
    post_worker_init:
    enable_stdio_inheritance: False
    preload_app: False
    pidfile: None
    worker_tmp_dir: None
    workers: 3
    max_requests_jitter: 0
    keyfile: None
    ssl_version: 2
    ciphers: TLSv1
    limit_request_line: 4094
    access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
    reload_extra_files: []
    worker_class: sync
    user: 0
    syslog_facility: user
    nworkers_changed:
    worker_connections: 1000
    reload: False
    reload_engine: auto
    ca_certs: None
    when_ready:
    syslog_addr: udp://localhost:514
    statsd_host: None
    bind: ['unix:/home/ubuntu/django_env/run/gunicorn.sock']
    threads: 1
    paste: None
    timeout: 30
    pre_request:
    loglevel: debug
    syslog: False
    pythonpath: None
    limit_request_fields: 100
    config: None
    pre_fork:
    daemon: False
    logconfig: None
    statsd_prefix:
    sendfile: None
    reuse_port: False
    group: 0
    initgroups: False
    graceful_timeout: 30
    tmp_upload_dir: None
    proc_name: Gaalgui20
    proxy_protocol: False
    on_reload:
    worker_abort:
    backlog: 2048
    spew: False
    on_starting:
    certfile: None
    cert_reqs: 0
    logger_class: gunicorn.glogging.Logger
    post_fork:
    secure_scheme_headers: {'X-FORWARDED-SSL': 'on', 'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https'}
    pre_exec:
    worker_exit:
    default_proc_name: gaalgui20.wsgi:application
    keepalive: 2
    limit_request_field_size: 8190
    check_config: False
    suppress_ragged_eofs: True
    raw_paste_global_conf: []
    disable_redirect_access_to_syslog: False
    capture_output: False
    [2018-10-02 19:34:23 +0100] [26632] [INFO] Starting gunicorn 19.9.0
    [2018-10-02 19:34:23 +0100] [26632] [DEBUG] Arbiter booted
    [2018-10-02 19:34:23 +0100] [26632] [INFO] Listening at: unix:/home/ubuntu/django_env/run/gunicorn.sock (26632)
    [2018-10-02 19:34:23 +0100] [26632] [INFO] Using worker: sync
    [2018-10-02 19:34:23 +0100] [26639] [INFO] Booting worker with pid: 26639
    [2018-10-02 19:34:23 +0100] [26640] [INFO] Booting worker with pid: 26640
    [2018-10-02 19:34:23 +0100] [26641] [INFO] Booting worker with pid: 26641
    [2018-10-02 19:34:24 +0100] [26632] [DEBUG] 3 workers


    and this is his content :


    #!/bin/bash

    NAME="Gaalgui20" # Name of the application
    DJANGODIR=/home/ubuntu/django_env/gaalgui20 # Django project directory
    SOCKFILE=/home/ubuntu/django_env/run/gunicorn.sock # we will communicte using this unix socket
    USER=root # the user to run as
    GROUP=root # the group to run as
    NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
    DJANGO_SETTINGS_MODULE=gaalgui20.settings # which settings file should Django use
    DJANGO_WSGI_MODULE=gaalgui20.wsgi # WSGI module name
    echo "Starting $NAME as `whoami`"

    # Activate the virtual environment

    cd $DJANGODIR
    source /home/ubuntu/django_env/bin/activate
    export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
    export PYTHONPATH=$DJANGODIR:$PYTHONPATH


    # Create the run directory if it doesn't exist

    RUNDIR=$(dirname $SOCKFILE)
    test -d $RUNDIR || mkdir -p $RUNDIR

    # Start your Django Unicorn
    # Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)

    exec gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --workers $NUM_WORKERS \
    --user=$USER --group=$GROUP \
    --bind=unix:$SOCKFILE \
    --log-level=debug \
    --log-file=-

    ReplyDelete
  62. hi i got a error while checking status using sudo supervisorctl status project name.
    "unix:///var/run/supervisor.sock no such file" this is the error thorwn by console

    and also used sudo supervisorctl status/start as you told above some post


    ReplyDelete
  63. This comment has been removed by the author.

    ReplyDelete
  64. In step 5 need to install: sudo apt-get install libxml2-dev libxslt1-dev

    ReplyDelete
  65. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.
    Java Training in Chennai

    Java Training in Bangalore

    Java Training in Hyderabad

    Java Training
    Java Training in Coimbatore

    ReplyDelete
  66. Awesome, I’m really thankful to you for this amazing blog. Visit Ogen Infosystem for creative website designing and development services in Delhi, India.
    Best Website Designing Company in Delhi

    ReplyDelete
  67. Very well written about Deploy Django Application. If you want videos of Deploy Django Application, please download vidmate. Vidmate With this app you can also stream live TV channels. In this, you will get more than 200 TV channels to stream live TV channels, in which all channels like news, games, animal planets etc. will be available. You can use this app completely free. In this you will get a search box in which you will be able to easily find whatever video you want to watch or download. You can also download Deploy Django Application and Vidmate from 9apps

    ReplyDelete
  68. Hello all. Great tutorial.
    I have a problem, I do

    $ sudo supervisorctl status L-StyleV2
    $ sudo service nginx status

    and it looks all right.
    But it's not showing on the web. It gives error 404.
    The only error I identified was when I make

    $ sudo gunicorn LStyleV2.wsgi:application --bind 0.0.0.0:8001

    it shows "ModuleNotFoundError: No module named 'LStyleV2' "

    Someone, please help me, I've been trying to solve this problem for a while.

    ReplyDelete
  69. Effectually composed data. it will probably be helpful to us all who utilizes it, comprising of me. continue to happen the sort produce results. For specific I will look at additional posts. This website page appears to income a tomfoolery measure of traffic.. MS Office 2019 Free Download With Crack

    ReplyDelete
  70. This comment has been removed by the author.

    ReplyDelete
  71. I really appreciate your valuable efforts and it was very helpful for me. Thank you so much...!
    Spousal Support Calculator
    Spousal Support Virginia

    ReplyDelete
  72. Very innovative post! This post is very interesting and thanks for sharing it with us...
    Separation Before Divorce
    Cost of Legal Separation VS Divorce

    ReplyDelete
  73. We appreciate you writing the best post we've ever seen. Very straightforward and clear. Do this consistently. This is quite beneficial. Outstanding information was shared. We'll return to your website.

    ReplyDelete
  74. "Great article! Thanks for sharing. Craft a winning SOP For Master program with our expert guidance. Learn how to showcase your unique skills, achievements, and aspirations to stand out from the competition. Create a compelling statement of purpose to secure your spot in your desired master's program.

    ReplyDelete
  75. Awesome, I’m really thankful to you for this amazing blog.
    web-designing-training-in-hyderabad

    ReplyDelete

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel