6

hi I need to deploy a django application on nginx . I install nginx and python-flup in my fedora I try this guide but nginx can't read my static file . in my project dir I used this command to run ​fastcgi:

[nima@ca005 bank]$ python ./manage.py runfcgi host=127.0.0.1 port=8080
[nima@ca005 bank]$ 

and this is my sample_project.conf in /etc/nginx/sites-enable/ :

server {
    listen 80;
    server_name 192.168.16.161;
    access_log /var/log/nginx/sample_project.access.log;
    error_log /var/log/nginx/sample_project.error.log;

    # https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
    location /static/ { # STATIC_URL
        alias /home/nima/workspace/bank/media/; # STATIC_ROOT
        expires 30d;
    }

    location /media/ { # MEDIA_URL
        alias /home/nima/workspace/bank/meli/static/; # MEDIA_ROOT
        expires 30d;
    }

    location / {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:8080;
        fastcgi_split_path_info ^()(.*)$;
    }
}

nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user              nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enable/*;



}

what should I do?!

nim4n
  • 1,813
  • 3
  • 21
  • 36

2 Answers2

7

Firstly, if you chose to use nginx, then use gunicorn, its the best option out there, and if you so wish to use Apache, then you use mod_wsgi.

This will show you how to use gunicorn. Just to tell you how well it serves, gunicorn is used by Instagram, because they claim that it gives them better performance.

Setting up gunicorn is very simple and easy to do, and this tutorial here, gives you all the things necessary to make it happen very quickly.

This is their website.

Lord Elrond
  • 13,430
  • 7
  • 40
  • 80
Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
  • 1
    I use gunicorn but It can't see my static when I run this command gunicorn_django -b 0.0.0.0:8000 – nim4n Jul 07 '13 at 11:24
  • 1
    @nim4n: Try this : http://stackoverflow.com/questions/12800862/django-static-files-under-gunicorn – Games Brainiac Jul 07 '13 at 11:34
  • the static part yes . but I have a problem with upstart part. when I try to start service It give me this error : root@ca005 nima]# service hello start Redirecting to /bin/systemctl start hello.service Failed to issue method call: Unit hello.service failed to load: No such file or directory. See system logs and 'systemctl status hello.service' for details. – nim4n Jul 07 '13 at 12:39
  • 1
    It may help, I wrote a guide for deploying Django with upstart, nginx and gunicorn : http://ponytech.net/blog/2013/09/10/django-deployement-ubuntu-upstart-nginx-gunicorn-and-virtualenvwrapper/ – Ponytech Sep 25 '13 at 09:15
  • What does gunicorn actually _do_ though? Whats its role? – ThorSummoner Jul 26 '15 at 17:02
2

Try this link using fastcgi mode
Or this link using uwsgi mode

Edit: fcgi mode is deprecated in django and will be removed. uwsgi is the favourable mode. One of the many references, check this

ashish
  • 2,090
  • 3
  • 17
  • 16