简体   繁体   English

在具有子域的单个Nginx上运行多个Rails应用程序

[英]Running Multiple Rails Apps on Single Nginx with Subdomains

I'm trying to figure out how to get a 2nd Rails app running on my server under a subdomain. 我试图弄清楚如何在子域下的服务器上运行第二个Rails应用程序。 Here's my setup: 这是我的设置:

(App1) Primary Rails app -> http://humani.se (App1)Primary Rails应用-> http://humani.se

(App2) Secondary Rails app -> http://supportme.humani.se (App2)Secondary Rails应用-> http://supportme.humani.se

The domain name is purchased through GoDaddy, and currently I have the subdomain pointing to http://humani.se:3000 (through the GoDaddy panel), which you can see works by just visiting that URL. 该域名是通过GoDaddy购买的,当前,我有一个指向http://humani.se:3000的子域(通过GoDaddy面板),您可以通过访问该URL来查看其作品。 I know, I know -- App1 is running in production and App2 is running in development, not good practice. 我知道,我知道-App1在生产中运行,而App2在开发中运行,不是很好的做法。 I'm just trying to see if I can get it working. 我只是想看看我能否使其正常工作。

Nginx Conf: 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;
}

Looks like it works, right? 看起来可行,对吧? Nope! 不! So all the routes seem to work EXCEPT from the Rails side. 因此,除了Rails以外,所有路线似乎都可以正常工作。 If you attempt to login (with any/no credentials), you will see the error, too. 如果尝试登录(使用任何/没有凭据),您也会看到该错误。 Basically, the URL helpers aren't working from the controller side. 基本上,URL帮助程序不是从控制器端工作的。 The ones in the views (anchor hyperlinks) work perfectly fine. 视图中的那些(锚定超链接)可以很好地工作。 From the server log: 从服务器日志:

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'

You can clearly see it's redirecting to the correct URL but then gets /.humani.se/ instead. 您可以清楚地看到它正在重定向到正确的URL,但随后获取/.humani.se/。 Someone somewhere must know about this! 某人必须知道这一点!

Any and all help is appreciated! 任何和所有帮助表示赞赏!

Thanks in advance, - Jeff 在此先感谢-杰夫

First of all you should not let godaddy point to the port, point both humani.se and supportme.humani.se to the same IP, and let nginx redirect each to the right app, like you can run app1 on port 3000 and app2 on port 3001 then do a simply proxy on nginx 首先你不应该让GoDaddy的点的端口,这两个点humani.sesupportme.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;
  }
}

this should do the trick, tell me what you get. 这应该可以解决问题,告诉我您得到了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM