使用nginx和uwsgi部署django app时,客户端无法连接到服务器

时间:2016-07-30 10:07:50

标签: python django nginx uwsgi

我一直试图在没有解决方案的情况下整整解决这个问题。现在,我的工作压力很大,我真的需要你的帮助。

我知道nginx正在使用netstat监听正确的端口'20154',我也运行了命令nginx -t并且没问题。日志没有错误,因为客户端无法访问服务器。

也许问题是uwsgi.init我不知道,所以我把我的cons文件和uwsgi init文件放在这里

我希望能在你的帮助下解决这个问题并更多地解决这个问题。

nginx.conf文件:

user user;
worker_processes 1;
pid /var/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";

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

    #include /etc/nginx/naxsi_core.rules;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

启用nginx的网站

upstream django {
   server unix:///home/ctag/env_Compass4D/Compass4D/Compass4D.sock; # for a file socket
}
server {
    listen 20154;         

    location /assets/ {

        root /home/ctag/env_Compass4D/Compass4D/;

    }

    location /doc/ {
        alias /usr/share/doc/;
        #alias /home/ctag/Compass4D/env_Compass4D/Compass4D
        autoindex on;
        #allow 127.0.0.1;

    }
    location / {
        #uwsgi_pass unix:/home/ctag/env_Compass4D/Compass4D/Compass4D.sock;
        proxy_pass            http://unix:/home/ctag/env_Compass4D/Compass4D/Compass4D.sock;
            #proxy_redirect        off;
            proxy_set_header      Host             $host;
            proxy_set_header      X-Real-IP        $remote_addr;
            proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
            client_max_body_size  10m;
        uwsgi_pass  django;
        include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
    location /Compass4D {
              root /home/ctag/env_Compass4D/Compass4D/;
    }   

uwsgi.init

# Compass4D_uwsgi.ini file
[uwsgi]

# Configuraciones Django
# ruta al directorio del proyecto (ruta completa)
chdir           = /home/ctag/env_Compass4D/Compass4D/
# Archivo wsgi de Django
module          = Compass4D.wsgi

# master
master          = true
# numero de procesos (trabajadores)
processes       = 5
# Ruta al socket
socket          = /home/ctag/env_Compass4D/Compass4D/Compass4D.sock
# Permisos del socket
chmod-socket    = 666

# Loggeo para detectar fallo al startup
#logto = /tmp/errlog

# Al cerrar limpiar el ambiente
vacuum          = true

1 个答案:

答案 0 :(得分:0)

这是适合我的新配置,您可以看到更改,也可以查看我必须使用的命令,谢谢。

新网站启用的文件:

#SEND EMAILS

        require '../includes/PHPMailer/PHPMailerAutoload.php';
        require '../includes/PHPMailer/config.php';

        if(isset($_POST['submit'])){

        $mail = new PHPMailer;

        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Host = $smtp_server_w;
        $mail->Username = $username_w;
        $mail->Password = $password_w;
        $mail->SMTPSecure = "ssl";
        $mail->Port = 465;

        $mail->setFrom("test@test.com", "Test Name");

        $sql_mail = "SELECT * FROM users";

        $run_mail = mysqli_query($conn, $sql_mail);
        while ($row_mail = mysqli_fetch_assoc($run_mail)) {

        $name = $row_mail["user_name"];
        $email = $row_mail["user_email"];
        $mail->ClearAddresses();

        $mail->addAddress('test@test.com', 'Test Name'); 
        $mail->addBCC($email, $name);

        $mail->isHTML(true);  // Set email format to HTML

        $bodyContent = "<p>Multiple Messages</p>";

        $mail->Subject = $row_mail['user_name'].", New job is available " ;
        $mail->Body    = $bodyContent;
        $mail->AltBody = $bodyContent;


        if(!$mail->send()) {
            echo "Message could not be sent.";
            $error = '<div class="alert alert-danger"><strong>Mailer Error: '. $mail->ErrorInfo.'</strong></div>';
        } else {
            $error = '<div class="alert alert-success"><strong>Message has been sent</strong></div>';
                }
            }
        }

我用于在后台运行服务器的uWSGI命令:

upstream django {
   server unix:///home/ctag/env_Compass4D/Compass4D/Compass4D.sock; # for a file socket

}
server {
        listen 80; ## listen for ipv4; this line is default and implied
        server_name ~^.*$;


        location /static/ {

                root /home/ctag/env_Compass4D/Compass4D/;

        }

        location /doc/ {
                alias /usr/share/doc/;

                autoindex on;


        }
        location / {
                #uwsgi_pass unix:/home/ctag/env_Compass4D/Compass4D/Compass4D.sock;
                proxy_pass            http://unix:/home/ctag/env_Compass4D/Compass4D/Compass4D.sock;
                #proxy_redirect        off;
                proxy_set_header      Host             $host;
                proxy_set_header      X-Real-IP        $remote_addr;
                proxy_set_header      X-Forwarded-For  $proxy_add_x_forwarded_for;
                client_max_body_size  10m;
                uwsgi_pass  django;
                include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
        location /Compass4D/ {
              root /home/ctag/env_Compass4D/Compass4D/;
        }