OS X [Yosemite]:无法使用nginx + unicorn运行rails app

时间:2014-10-30 21:31:24

标签: ruby-on-rails nginx unicorn osx-yosemite

我正在尝试在这个环境中测试一个非常基本的Rails应用程序(称为simpleapp),(Nginx安装并运行良好的html / php网站),Unicorn正在启动,但在应用程序请求时没有任何反应。

我在我的localhost上使用'dnmasq'和.dev域的解析器

DNMASQ& RESOLVER

#  my brew --prefix)/etc/dnsmasq.conf is :
address=/.dev/127.0.0.1

# my /etc/resolved/dev is :  
nameserver 127.0.0.1

NGINX

   # my /user/local/etc/nginx/nginx.conf is :

    worker_processes  1;

    error_log  /usr/local/etc/nginx/logs/error.log debug;

    events {
        worker_connections  1024;
    }

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

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /usr/local/etc/nginx/logs/access.log  main;
        sendfile            on;
        keepalive_timeout   65;
        index index.html index.php;
        include /usr/local/etc/nginx/sites-enabled/*; 
    }

我在/ user / local / etc / nginx / sites-available(ln到站点启用)代理到端口3001

   # /user/local/etc/nginx/sites-available/simpleapp :
        server {
      listen       80;
      server_name  simpleapp.dev;
      client_max_body_size 4G;
      keepalive_timeout 5;

      root  /Users/myself/Developpement/RAILS-41/simpleapp;

      location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_pass_header X-Accel-Redirect;
        proxy_read_timeout 300s;
        if (!-f $request_filename) {
          proxy_pass   http://127.0.0.1:3001;
          break;
        }
      }
    }

UNICORN

我正在使用'foreman'来启动我的独角兽应用服务器

# in my simple/Procfile I got :
web: bundle exec unicorn -p 3001 -c ./config/unicorn.conf.rb

#my config/unicorn.conf.rb is as simple as :
listen 3001
worker_processes 2
pid "./tmp/pids/unicorn.pid"
stderr_path "./log/unicorn-error.log"
stdout_path "./log/unicorn.log"a

我重装了我的nginx并开始领班:

sudo nginx -s relaod
foreman start
19:13:30 web.1  | started with pid 16860

UNICORN LOG

    I, [2014-10-30T19:15:56.961299 #17023]  INFO -- : listening on addr=0.0.0.0:3001 fd=9
    I, [2014-10-30T19:15:56.961785 #17023]  INFO -- : worker=0 spawning...
    I, [2014-10-30T19:15:56.963273 #17023]  INFO -- : worker=1 spawning...
    I, [2014-10-30T19:15:56.964391 #17023]  INFO -- : master process ready
    I, [2014-10-30T19:15:56.965524 #17119]  INFO -- : worker=0 spawned pid=17119
    I, [2014-10-30T19:15:56.966147 #17119]  INFO -- : Refreshing Gem list
    I, [2014-10-30T19:15:56.966512 #17120]  INFO -- : worker=1 spawned pid=17120
    I, [2014-10-30T19:15:56.967227 #17120]  INFO -- : Refreshing Gem list
    I, [2014-10-30T19:16:09.746993 #17119]  INFO -- : worker=0 ready
    I, [2014-10-30T19:16:09.746993 #17120]  INFO -- : worker=1 ready

在我的浏览器中,我尝试访问简单的rails应用程序:

   http://simpleapp.dev

但没有任何事情发生,也没有日志信息......

我哪里错了?

1 个答案:

答案 0 :(得分:0)

解决了它,将上游块添加到nginx.conf

....
include /usr/local/etc/nginx/sites-enabled/*; 

upstream upstream_server {
    server localhost:3001;
}

并修改简单服务器描述:

server {
    listen       80;
    server_name  simpleapp.dev;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://upstream_server;
    }
}

所以我可以有多个rails app(定义多个上游块...