使用nginx反向代理部署Tornado失败,无错误提示



我正试图部署我的龙卷风应用程序与Nginx作为代理。我正试图在Ramnode VPS (512 CVZ)上运行此配置为:

  • 512mb ram
  • 512MB VSwap
  • 2 CPU Core Access
  • 120GB SSD-Cached HDD空间
  • <
  • 1 gbps港口/gh>

我现在没有使用supervisor,我手动启动了我的tornado进程的四个实例:

sudo python /home/magneto/pricechase/main.py --port=8000 &
sudo python /home/magneto/pricechase/main.py --port=8001 &
sudo python /home/magneto/pricechase/main.py --port=8002 &
sudo python /home/magneto/pricechase/main.py --port=8003 &

和我可以访问网站现在在pricechase。In:8000 to price . In:8003

我创建了一个新用户nginx,并赋予我的项目目录权限:

sudo adduser --system --no-create-home --disabled-login --disabled-password --group nginx
sudo chown -R nginx:nginx /home/magneto/pricechase/

下面是我的项目的配置文件,位于/etc/nginx/sites-enabled/pricechase.in

user nginx;
worker_processes 5;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
    use epoll; 
}
http{
    proxy_next_upstream error;
    upstream tornadoes { 
        server 127.0.0.1:8000;
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
        server 127.0.0.1:8003;
    }
    include /etc/nginx/mime.types;
    default_type application/octet-stream;  
    access_log /var/log/nginx/access.log;
    keepalive_timeout 65;
    proxy_read_timeout 200;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1000;
    gzip_proxied any;
    gzip_types text/plain text/html text/css text/xml
               application/x-javascript application/xml
               application/atom+xml text/javascript;

    server { 
        listen 80;
        server_name pricechase.in www.pricechase.in;
        location /static/ {
            root /home/magneto/pricechase/static; 
            if ($query_string) {
                expires max; 
            }
        }
        location / {
            proxy_pass_header Server; 
            proxy_set_header Host $http_host; 
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_set_header X-Scheme $scheme; 
            proxy_pass http://tornadoes;
        } 
    }
}

当我尝试重新启动nginx服务时,我得到以下错误:

Restarting nginx: nginx: [emerg] unknown directive "user" in /etc/nginx/sites-enabled/pricechase.in:1
nginx: configuration file /etc/nginx/nginx.conf test failed

正如这里的答案所示,我在/etc/nginx/nginx.conf中注释了以下行:

# include /etc/nginx/sites-enabled/*;

现在我可以启动/重新启动它,但是当我输入pricechase。它没有打开网站。它也不能访问静态文件,例如:http://pricechase.in/static/css/tooltipster.css位于/home/magneto/pricechase/static/css/tooltipster.css

/etc/nginx/nginx.conf的内容如下:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
    worker_connections 768;
    # multi_accept on;
}
http {
    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;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    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;
    ##
    # Virtual Host Configs
    ##
    include /etc/nginx/conf.d/*.conf;
    # include /etc/nginx/sites-enabled/*;
    # include /etc/nginx/sites-enabled/pricechase.in;
}
  • 我如何调试这个?
  • 为什么它没有记录任何错误?我检查了访问和错误日志(位于/var/log/nginx/)关于nginx配置文件有什么建议/改进吗?
  • 如果我理解正确,/etc/nginx/nginx.conf就像一个基本模板,我需要任何其他主机的所有常见配置都应该包含在其中,对吧?
  • 如果我想添加另一个域并服务不同的龙卷风实例,我想我必须在sites-enabled中添加新的conf,但是会有任何冲突吗?例如,我希望http://abc.xyz.com提供位于/home/magneto/blog的静态内容,http://pqrs.com提供端口8005至8008的龙卷风过程。

在sites-enabled中的配置片段应该只包含"http"块中的部分;其他部分只能出现在顶层的nginx.conf中。

相关内容

最新更新