【问题标题】:Unable to deploy Tornado with nginx reverse proxy, no errors are displayed无法使用 nginx 反向代理部署 Tornado,不显示错误
【发布时间】:2014-08-26 13:41:19
【问题描述】:

我正在尝试使用 Nginx 作为代理部署我的 Tornado 应用程序。我正在尝试在配置如下的 Ramnode VPS (512 CVZ) 上运行它:

  • 512MB 内存
  • 512MB 交换
  • 2 CPU 核心访问
  • 120GB SSD 缓存硬盘空间
  • 1Gbps 端口

我现在没有使用主管,我手动启动了我的龙卷风进程的四个实例:

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 到 pricechase.in:8003 访问该网站

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

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

以下是我项目的 conf 文件,位于 /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

正如here 的答案所示,我在/etc/nginx/nginx.conf 中评论了以下行:

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

现在我可以启动/重新启动它,但是当我输入 pricechase.in 时,它并没有打开网站。它也不能访问静态文件,例如: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/bloghttp://pqrs.com 的静态内容提供服务,为端口8005 到8008 的龙卷风进程提供服务。

【问题讨论】:

  • 我将/etc/nginx/sites-enabled/pricechase.in 移动到etc/nginx/nginx.conf 并且它按预期工作。不知道那是不是我应该做的。

标签: python nginx proxy tornado


【解决方案1】:

启用站点的配置片段应仅包含“http”块内的部分;其他部分只能出现在最顶层的 nginx.conf 中。

【讨论】:

    猜你喜欢
    • 2010-11-07
    • 2020-10-23
    • 1970-01-01
    • 2018-03-06
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2015-09-11
    相关资源
    最近更新 更多