6

嗨,我需要在 nginx 上部署一个 django 应用程序。我在我的 Fedora 中安装了 nginx 和 python-flup 我尝试了本指南,但 nginx 无法读取我的静态文件。在我的项目目录中,我使用此命令运行 fastcgi:

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

这是我在 /etc/nginx/sites-enable/ 中的 sample_project.conf :

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/*;



}

我应该怎么办?!

4

2 回答 2

7

首先,如果你选择使用 nginx,那么使用gunicorn,它是最好的选择,如果你想使用 Apache,那么你使用mod_wsgi.

将向您展示如何使用 gunicorn。只是为了告诉你它的服务有多好,Instagram 使用 gunicorn,因为他们声称它可以为他们提供更好的性能。

设置gunicorn非常简单易行,这里的教程为您提供了快速完成所需的所有内容。

是他们的网站。

于 2013-07-07T10:59:05.690 回答
2

使用 fastcgi 模式尝试
链接 或使用uwsgi 模式尝试此链接

编辑:fcgi 模式在 django 中已弃用,将被删除。uwsgi 是有利的模式。众多参考资料之一,请检查此

于 2013-10-01T11:00:12.730 回答