我想在本地MAC上安裝Rails和Puma來實踐一些設置的Nginx。最終我會有兩個應用程序運行,所以Nginx會負載平衡它們。Nginx在本地作爲開發環境在OS X上爲Puma服務Rails應用程序
For Rails and Puma我有下一個。
Procfile有:
web: bundle exec puma -C config/puma.rb
puma.rb有:
threads 0,16
workers 1
port 3000
environment "production"
bind "unix:///path_to_my_app/tmp/sockets/puma.sock"
preload_app!
「工頭開始」 火起來的應用
09:28:15 web.1 | started with pid 31442
09:28:16 web.1 | [31442] Puma starting in cluster mode...
09:28:16 web.1 | [31442] * Version 2.13.4 (ruby 2.2.1-p85), codename: A Midsummer Code's Dream
09:28:16 web.1 | [31442] * Min threads: 0, max threads: 16
09:28:16 web.1 | [31442] * Environment: production
09:28:16 web.1 | [31442] * Process workers: 1
09:28:16 web.1 | [31442] * Preloading application
09:28:19 web.1 | [31442] * Listening on tcp://0.0.0.0:3000
09:28:19 web.1 | [31442] * Listening on unix:///path_to_my_app/tmp/sockets/puma.sock
09:28:19 web.1 | [31442] Use Ctrl-C to stop
09:28:19 web.1 | [31442] - Worker 0 (pid: 31444) booted, phase: 0
應用程序正在運行,我可以訪問它使用127.0.0.1:3000,0.0.0.0:3000或localhost:3000
現在我想用Nginx來說明它。
我與釀造安裝Nginx的,並得到版本1.8.0
的nginx.conf位於位於/ usr/local/etc中/ nginx的,看起來像下面。我刪除了一些對可讀性註釋行:
worker_processes 1;
error_log logs/error.log;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location/{
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
}
include servers/*;
}
那麼,真正應該與Rails應用程序連接配置服務器文件夾內。在那裏我有一個名爲micro.conf的文件。
upstream app {
server 127.0.0.1:3000;
#server unix:///path_to_my_app/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 8080 default;
root /path_to_my_app/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
現在,如果我去本地主機:8080不應該最終服務於Rails應用程序?它只是去歡迎Nginx頁面。
如果我去Rails應用程序的資源之一,像本地主機:8080 /接觸,我可以在日誌中看到這一點:
2015/10/13 10:10:19 [error] 31614#0: *2 open() "/usr/local/Cellar/nginx/1.8.0/html/contacts" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /contacts HTTP/1.1", host: "localhost:8080"
這清楚地表明,它不是尋找的應用程式中正確的地方。
我得到了與上游套接字相同的結果。任何想法讓這個非常基本的設置工作?
嗨,你爲什麼使用IP和端口上游,而不是套接字?謝謝。 – Wen
嗨,不幸的是它已經1年了,幾乎完全是這樣,我可以回想起細節。我想我有一些問題需要插座才能工作。 IP和套接字比抽象套接字神祕連接更具人類可讀性。但我真的不記得。 – Pod