[英]Running Multiple Rails Apps on Single Nginx with Subdomains
我試圖弄清楚如何在子域下的服務器上運行第二個Rails應用程序。 這是我的設置:
(App1)Primary Rails應用-> http://humani.se
(App2)Secondary Rails應用-> http://supportme.humani.se
該域名是通過GoDaddy購買的,當前,我有一個指向http://humani.se:3000的子域(通過GoDaddy面板),您可以通過訪問該URL來查看其作品。 我知道,我知道-App1在生產中運行,而App2在開發中運行,不是很好的做法。 我只是想看看我能否使其正常工作。
Nginx Conf:
# Primary Application Server
upstream humanise {
# for UNIX domain socket setups:
server unix:/home/jeff/srv/humani.se/tmp/sockets/unicorn.sock fail_timeout=0;
# server localhost:8080;
}
server {
server_name humani.se www.humani.se;
# path for static files
root /home/jeff/srv/humani.se/public;
try_files $uri/index.html $uri.html $uri @humanise;
location @humanise {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# proxy_pass http://unix:/home/jeff/srv/humani.se/tmp/sockets/unicorn.sock;
proxy_pass http://humanise;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
# Secondary Application Server
upstream supportme {
server localhost:3000;
}
server {
server_name supportme.humani.se;
try_files $uri/index.html $uri @supportme;
location @supportme {
proxy_pass http://supportme;
proxy_set_header Host $host;
proxy_buffering off;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
看起來可行,對吧? 不! 因此,除了Rails以外,所有路線似乎都可以正常工作。 如果嘗試登錄(使用任何/沒有憑據),您也會看到該錯誤。 基本上,URL幫助程序不是從控制器端工作的。 視圖中的那些(錨定超鏈接)可以很好地工作。 從服務器日志:
Started POST "/login" for 127.0.0.1 at 2014-06-20 13:51:56 -0400
Processing by UsersController#login as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"eJvcm5auwCWFzw2BRY8DLzv8W5I3z0W529MXAJRLJb0=", "user"=>{"email"=>"ijt", "password"=>"[FILTERED]"}, "commit"=>"Sign in"}
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'ijt' LIMIT 1
Redirected to http://supportme.humani.se/
Completed 302 Found in 4ms (ActiveRecord: 0.5ms)
Started GET "/.humani.se/" for 127.0.0.1 at 2014-06-20 13:51:56 -0400
ActionController::RoutingError (No route matches [GET] "/.humani.se"):
actionpack (4.0.4) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.0.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.0.4) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.4) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.4) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.4) lib/rails/engine.rb:511:in `call'
railties (4.0.4) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/jeff/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/jeff/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/jeff/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
您可以清楚地看到它正在重定向到正確的URL,但隨后獲取/.humani.se/。 某人必須知道這一點!
任何和所有幫助表示贊賞!
在此先感謝-傑夫
首先你不應該讓GoDaddy的點的端口,這兩個點humani.se
和supportme.humani.se
相同的IP,並讓每個nginx的重定向到合適的應用程序,比如你可以在端口上運行APP1 3000
和App2上端口3001
然后在nginx上做一個簡單的代理
server {
server_name humani.se;
location / {
proxy_pass http://localhost:3000;
}
}
server {
server_name support.humani.se;
location / {
proxy_pass http://localhost:3001;
}
}
這應該可以解決問題,告訴我您得到了什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.