【问题标题】:OS X [Yosemite] : cannot run rails app using nginx + unicornOS X [Yosemite]:无法使用 nginx + unicorn 运行 rails 应用程序
【发布时间】:2014-12-27 02:59:46
【问题描述】:

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

我在本地主机上使用 'dnmasq' 和 .dev 域的解析器

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

   # 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 to sites-enabled) 中有一个代理到端口 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;
        }
      }
    }

独角兽

我正在使用“工头”来启动我的独角兽应用服务器

# 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

独角兽日志

    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

但是什么也没发生,也没有日志信息....

我哪里错了??

【问题讨论】:

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


    【解决方案1】:

    解决了,在 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 应用程序(定义多个上游块...

    【讨论】:

      猜你喜欢
      • 2015-05-22
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 2015-08-15
      • 1970-01-01
      • 2011-08-02
      • 2012-12-19
      • 2013-08-10
      相关资源
      最近更新 更多