连接被ImportError拒绝

时间:2014-12-22 18:53:57

标签: django nginx uwsgi

我使用Django + nginx + uwsgi。

cat cat /var/log/nginx/error.log:

connect() to unix:///home/user/app/app.sock failed (111: Connection refused) while connecting to upstream

所以,我去看uwsgi的日志:

ImportError: No module named site

我搜索所有关于此的网页,可能是它的django错误?如何解决?

nginx.conf:

user www-data;
worker_processes 2;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    # gzip_proxied any;
    gzip_comp_level 6;
    # gzip_buffers 16 8k;
    #gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/mysite_nginx.conf;
    #include /etc/nginx/sites-enabled/*;

}   

mysite_nginx.conf:

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/user/app/app.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen 80;
    #listen [::]:80 default_server;
    # the domain name it will serve for
    server_name IP!; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 2M;

    # Django media
    location /datastore  {
        alias /home/user/app/app/files/dynamic;
        access_log        off;
        expires           30d;
    }

    location /core {
        alias /home/user/app/app/files/static_content;
        access_log        off;
        expires           30d;
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/user/app/uwsgi_params; # the uwsgi_params file you installed
    }
}

app_uwsgi.ini:

# app_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/user/app/
# Django's wsgi file
module          = app.wsgi:application
# the virtualenv (full path)
home            = /home/user/app/

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /home/user/app/app.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 666
# clear environment on exit
vacuum          = true
#plugin = python,http
max-requests=5000
daemonize = /home/user/app/logs/app.log

1 个答案:

答案 0 :(得分:0)

需要:

#home            = /home/user/app/
pythonpath = /usr/local/lib/python2.7/dist-packages