2014-10-30 61 views
0

我想在這種環境下測試一個非常基本的Rails應用程序(稱爲simpleapp),(Nginx已安裝並且可以正常運行html/php網站),獨角獸正在啓動,但沒有發生應用程序請求。OS X [Yosemite]:無法運行使用nginx +獨角獸的rails應用程序

我使用 '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/*; 
    } 

和我在/用戶/本地/ 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

我使用 '工頭',開始我的獨角獸應用服務器

# 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 

,但沒有發生,也沒有日誌信息....

我在哪裏錯了?

回答

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

所以可以有多個滑軌應用程序(定義多個上行流塊.. 。

相關問題