【问题标题】:Nginx server configuration for Thin, Faye & RedisThin、Faye 和 Redis 的 Nginx 服务器配置
【发布时间】:2012-07-17 15:25:51
【问题描述】:

/etc/nginx/nginx.conf 看起来像:

user  deploy;
worker_processes  5;

error_log  logs/error.log;

events {
    worker_connections  1024;
    use epoll;
}

http {

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


    sendfile        on;

    keepalive_timeout  65;

    upstream foreman4000 {
        server x.x.x.x:4000;
        server x.x.x.x:4001;
        server x.x.x.x:4002;
        server x.x.x.x:4003;
        server x.x.x.x:4004;
    } 

   server {
      listen       80;
      server_name  x.x.x.x;    #server IP
      access_log  /opt/nginx/foreman4000.access.log;
      location / {
        proxy_pass http://foreman4000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
      }
   }
}

这里我使用 gem foreman,它使用 upstart 来管理所有进程并通过一个命令启动所有服务器

我在项目的主目录中创建了 Procfile,其中包含:

redis:  redis-server
thin:   bundle exec thin start -p $PORT
faye:   rackup faye.ru -E production -s thin

添加到 Gemfile:

gem 'foreman'
gem 'thin'
gem "foreman-export-daemontools", "~> 0.0.1"

在本地运行 bundle install 来编辑 Gemfile.lock 在服务器上部署项目。

启动 Nginx

deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx stop   [ OK ]
deploy@dcards101:/opt/nginx/conf$ sudo /etc/init.d/nginx srart  [ OK ]

从 Procfile 导出数据到 Upstart

deploy@dcards101:/var/www/cards/current$ rvmsudo foreman export upstart -a cards -u root

启动的应用程序

deploy@dcards101:/var/www/cards/current$ rvmsudo start cards

现在一切都必须很好,但我在服务器上看到的只是

502 Bad Gateway

nginx/1.0.15

日志说:

2012/07/17 17:22:30 [error] 11593#0: *148 no live upstreams while connecting to upstream, client: x.x.x.x, server: x.x.x.x, request: "GET / HTTP/1.1", upstream: "http://foreman4000/", host: "x.x.x.x"

请尽你所能提供帮助。服务器——Ubuntu 10 LTS。

【问题讨论】:

    标签: ruby-on-rails nginx thin faye foreman


    【解决方案1】:

    得到同样的错误以这种方式解决:

    先安装nginx_tcp_proxy_module

    (我遵循this 教程,但将其更改为使用passenger 和thin with nginx)

    将 tcp 部分添加到您的 nginx.conf 中:

    tcp {
        upstream websockets {
            ## node processes
            server 12.34.56.78:9292; 
            check interval=300 rise=2 fall=5 timeout=1000;
        }   
    
        server {
            listen 9200;
            server_name domain.org;
            tcp_nodelay on;
            proxy_pass websockets;
        }
    }
    

    80 端口对我不起作用

    在那之后我仍然收到来自 faye/privat_pub 的空回复,但有一个极其简单的解决方案:

    RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production
    

    看private_pub - Issue #29

    现在一切正常,除了 chrome 如何触发 2 次​​p>

    (并且我需要一个用于机架的守护进程)

    希望对你也有帮助

    【讨论】:

    • 非常感谢,但这并不是我所需要的。我想我的错在上游的某个地方,在 Rails 服务器中。但我找不到问题所在。如果我能很好地开始 Thin,我想一切都会好起来的。
    【解决方案2】:

    我认为您的问题是您将应用服务器和 faye 服务器放在同一个上游!

    如果我正确掌握了上游和工头的方法,您的第一个访问者将获得第二个 faye 的应用程序,依此类推。 (也许我错了,因为我不认识工头……但如果工头将所有可用服务器共享给所有服务,那可能是你的问题)

    我说尝试 capistrano 而不是工头 .. 这样你就可以完全控制哪个服务器从哪里开始 .. 因为在我的主机上,http 不适用于 private_pub(因为 nginx)所以我必须安装 nginx_tcp_proxy_module 才能获得在我的 nginx.conf 中工作的 tcp 块

    或者只是通过 ssh 逐个服务器尝试查找错误

    【讨论】:

      猜你喜欢
      • 2019-04-03
      • 2017-05-12
      • 2013-04-06
      • 1970-01-01
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2013-10-05
      相关资源
      最近更新 更多