我正在尝试弄清楚如何让第二个 Rails 应用程序在我的服务器上的子域下运行。这是我的设置:
(App1) Primary Rails 应用程序 -> http://humani.se
(App2) 辅助 Rails 应用程序 -> http://supportme.humani.se
域名是通过GoDaddy购买的,目前我的子域名指向http://humani.se:3000 (通过 GoDaddy 面板),您只需访问该 URL 即可看到它的效果。我知道,我知道——App1 在生产环境中运行,而 App2 在开发环境中运行,这不是好的做法。我只是想看看我是否能让它工作。
Nginx session :
# 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 助手不在 Controller 端工作。 View 中的那些( anchor 超链接)工作得很好。来自服务器日志:
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重定向每个到正确的应用程序,就像你可以在端口 3000
上运行 app1 和在端口 3001
上运行 app2 然后在 nginx 上做一个简单的代理
server {
server_name humani.se;
location / {
proxy_pass http://localhost:3000;
}
}
server {
server_name support.humani.se;
location / {
proxy_pass http://localhost:3001;
}
}
这应该可以解决问题,告诉我你得到了什么。
关于ruby-on-rails - 使用子域在单个 Nginx 上运行多个 Rails 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24333109/