简体   繁体   English

Windows for Rails应用程序上的Nginx + Thin配置

[英]Nginx + Thin config on Windows for Rails app

I'm somewhat confused about using Nginx and Thin for serving my Rails 3.2 app. 我对于使用Nginx和Thin服务我的Rails 3.2应用感到有些困惑。 Previously I had Thin serving my Rails app on Windows Server 2008 R2 without any issues. 以前,我曾在Windows Server 2008 R2上为我的Rails应用提供Thin服务,没有任何问题。 I would start Thin on the production server specifying the server's IP address on port 80 like such: 我将在生产服务器上启动Thin,在端口80上指定服务器的IP地址,例如:

rails server thin -b 10.xx.x.xxx -p 80 -e production

Now, I'm trying to add Nginx to the mix and I'm confused about how I should start Thin and how I should configure Nginx to forward to Thin. 现在,我试图将Nginx添加到组合中,而对于如何启动Thin以及如何配置Nginx转发到Thin感到困惑。

For example, now that Nginx is listening on port 80, should I start Thin locally on a different port? 例如,既然Nginx正在侦听端口80,是否应该在其他端口上本地启动Thin? Like 0.0.0.0:3000 (or 127.0.0.1:3000)? 像0.0.0.0:3000(或127.0.0.1:3000)一样? Or do I start Thin like I did before on 10.xx.x.xxx:80? 还是我像以前在10.xx.x.xxx:80上启动Thin一样?

In my Nginx conf file do I specify the upstream servers as localhosts, or the machine's IP address? 在我的Nginx conf文件中,我是否将上游服务器指定为localhost或计算机的IP地址? I'm not really sure what it's for. 我不太确定这是干什么的。

upstream mywebapp_thin {
  server 0.0.0.0:3000;
}

server {
    listen       80;
    server_name  mywebserver www.mywebserver;
    # locations et. al. excluded for brevity...

Most examples I see have the upstream servers running on ports 3000 or 5000. I'm wondering if those examples are really for a development setup, and not production? 我看到的大多数示例的上游服务器都在端口3000或5000上运行。我想知道这些示例是否真的用于开发设置而不是生产环境? Or does Thin need to run on a different port other than 80 since Nginx is listening on it now? 还是因为Nginx正在监听,Thin是否需要在80以外的其他端口上运行?

I noticed that my web app does not respond to the basic urls (mywebserver/projects) unless I add the port Thin is running on (mywebserver:3000/projects) 我注意到我的Web应用程序不会响应基本URL(mywebserver / projects),除非我添加运行Thin的端口(mywebserver:3000 / projects)

You are correct that you must start thin up on a new port due to the fact that nginx is already running on that port. 您是正确的,因为nginx已经在该端口上运行,因此必须在新端口上开始精简配置。 It is generally best to start a server that is not the one that users should directly access on the loopback interface so that users can't access it, therefore the command to start up thin should be something like: 通常,最好启动一台服务器,该服务器不是用户应直接在环回接口上访问的服务器,以便用户无法访问它,因此,启动thin的命令应类似于:

rails server thin -b 127.0.0.1 -p 3000 -e production

After doing that, you should change your upstream block to be: 之后,您应该将upstream块更改为:

upstream mywebapp_thin {
  server 127.0.0.1:3000;
}

That said, if you do not have multiple upstreams, you gain nothing by using the upstream module. 也就是说,如果您没有多个上游,则使用上游模块不会有任何好处。 You should just proxy_pass directly to your upstream. 您应该只将proxy_pass直接传递到上游。 As it is, 0.0.0.0 is not a valid IP address, so that is likely why you are unable to access anything. 实际上, 0.0.0.0不是有效的IP地址,因此这很可能就是您无法访问任何内容的原因。

I also notice that you do not have www.mywebserver.com or webserver.com in the server_name directive, not sure if you left that out on purpose. 我还注意到, server_name指令中没有www.mywebserver.comwebserver.com ,不确定是否故意删除了该名称。

What does the error log say when you make a request? 发出请求时,错误日志怎么说? If these changes don't fix your problems, you'll probably need to post the error log as well as your full config. 如果这些更改不能解决您的问题,则可能需要发布错误日志以及完整的配置。

On a side note, if you are deploying on Windows, you might consider using JRuby and using trinidad as a server instead of thin, or using warbler to package your app so that it can be deployed on your Java application server of choice. 附带说明一下,如果您要在Windows上进行部署,则可以考虑使用JRuby并将特立尼达作为服务器而不是瘦服务器,或者使用warbler打包您的应用程序,以便可以将其部署在您选择的Java应用程序服务器上。 This doesn't change anything with your nginx configuration, though. 但是,这对于您的nginx配置没有任何改变。

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

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