简体   繁体   English

OS X [Yosemite]:无法使用Nginx +独角兽运行Rails应用

[英]OS X [Yosemite] : cannot run rails app using nginx + unicorn

I am trying to test a very basic Rails app (called simpleapp) in this environment, ( Nginx is installed and running fine for html/php web sites) , Unicorn is starting but nothing happen upon application request. 我正在尝试在这种环境中测试一个非常基本的Rails应用程序(称为simpleapp)(已安装Nginx并在html / php网站上正常运行),Unicorn正在启动,但在应用程序请求后没有任何反应。

I am using 'dnmasq' and a resolver for .dev domains on my localhost 我在本地主机上使用'dnmasq'和.dev域的解析器

DNMASQ & RESOLVER DNMASQ和解析器

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

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

NGINX 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/*; 
    }

and I have in /user/local/etc/nginx/sites-available ( ln to sites-enabled) a proxy to port 3001 而且我在/ user / local / etc / nginx / sites-available(启用站点)中有一个到端口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 独角兽

I am using 'foreman' to start my unicorn app server 我正在使用“ foreman”启动我的独角兽应用服务器

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

and

#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

I reload my nginx and start foreman : 我重新加载我的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

in my browser I try to reach the simple rails app : 在我的浏览器中,我尝试访问简单的Rails应用程序:

   http://simpleapp.dev

but nothing happen, and no log information.... 但没有任何反应,也没有日志信息。

where am I wrong ?? 我在哪里错了?

solved it , adding an upstream block into nginx.conf 解决了它,在nginx.conf中添加了一个上游块

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

upstream upstream_server {
    server localhost:3001;
}

and modifying the simple server description : 并修改简单的服务器描述:

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;
    }
}

so I can have multiple rails app ( defining multiple upstreams block... 所以我可以有多个Rails应用程序(定义多个上游块...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM