简体   繁体   English

Nginx在子uri上托管单个Rails应用程序

[英]Nginx hosting a single Rails app on sub uri

Background: 背景:

  • I am running a debian 7 server behind a reverse proxy. 我在反向代理后面运行debian 7服务器。
  • I have a rails 4 app running ruby 2.0.0-p247 我有一个运行ruby 2.0.0-p247的rails 4应用程序
  • I am using nginx 我正在使用nginx
  • Server is accessed by navigating to: server-name.foo.dev where foo.dev is the internal reverse proxy domain. 通过导航到:server-name.foo.dev来访问服务器,其中foo.dev是内部反向代理域。
  • I am unable to use passenger to deploy the app. 我无法使用乘客来部署应用程序。
  • This will be the only app running on the server. 这将是服务器上运行的唯一应用程序。

Problem: 问题:

I need to host the rails app on a sub uri or context root path on the server behind the reverse proxy, so that when users navigate to the website, the url for the root path looks like this: 我需要在反向代理后面的服务器上的子uri或上下文根路径上托管rails app,这样当用户导航到网站时,根路径的url如下所示:

  • server-name.foo.dev/rails_app, where rails_app would be the root of the rails app. server-name.foo.dev/rails_app,其中rails_app将成为rails应用程序的根目录。

How would I set this up in nginx sites-enabled config file, and is there anything I would have to modify on the rails app to allow it to sever the correct paths to static content. 我如何在启用了nginx站点的配置文件中进行设置,并且我需要在rails应用程序上修改任何内容以允许它切断到静态内容的正确路径。

I strongly recommend to use Unicorn instead of Passenger. 我强烈建议使用Unicorn而不是Passenger。 You can set up both of them(Unicorn and Nginx) as reverse proxy. 您可以将它们(Unicorn和Nginx)设置为反向代理。 This link will be pretty good paper for you.. 这个链接对你来说是相当不错的论文..

Again, you 'rewrite'(Nginx route feature) /rails_app to rails application's Unicorn socket file(usually using upstream). 再次,你'重写'(Nginx路由功能)/ rails_app到rails应用程序的Unicorn套接字文件(通常使用上游)。

See also below code snippets. 另请参见下面的代码段。

partial nginx.conf 部分nginx.conf

location ~* ^/(rails_app)/ {
  root   /your/rails/home;
  index  index.html index.htm;
  proxy_pass http://socket_proxy_name;
}

partial snippet for proxy_pass proxy_pass的部分代码段

upstream socket_proxy_name{
  server unix:/your/socket/paht.sock fail_timeout=0;
}

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

相关问题 在Thins上托管Rails应用,在子uri上托管Nginx,在反向代理后面 - Hosting Rails app on Thins, Nginx on a sub uri, behind a reverse proxy 使用(unicorn和nginx)在rails app uri上部署sinatra app - Deploying sinatra app on rails app sub uri using( unicorn and nginx) 使用unicorn和nginx将另一个Rails应用程序部署到sub uri - Deploying another rails app to a sub uri with unicorn and nginx static 登陆页面和 Rails 应用在子 uri 上与 Dokku 的相同域托管 - Same domain hosting of both static landing page and Rails app on sub-uri with Dokku 将rails 3.2.12 app(带引擎)部署到nginx / passenger上的SUB URI时出现404 Not Found错误 - 404 Not Found error in deploying rails 3.2.12 app (with engines) to SUB URI on nginx/passenger 仅重新启动运行在承载许多乘客应用程序的VPS上的Passenger / nginx上的单个Rails应用程序 - Restart only a single Rails app running on Passenger / nginx on VPS hosting many passenger apps 在域的子uri上部署rails app - Deploy rails app at sub uri of a domain 与Passenger一起部署Nginx时出现Rails Sub URI 403禁止的错误 - Rails Sub URI 403 Forbidden Errors when Deploying with Passenger for Nginx 如何使用sub uri使用passenger / nginx登录rails 3.2.12 - How to use sub uri to login in rails 3.2.12 with passenger/nginx 单个Rails应用程序通过缓存托管多个域 - A single Rails app hosting multiple domains with caching
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM