简体   繁体   English

Nginx Rails网站和拥有多个端口的Passenger

[英]Nginx Rails website and Passenger with multiple ports

I would like to run two versions of my rails site, one for production and one for development. 我想运行两个版本的rails网站,一个用于生产,一个用于开发。 The production one will listen on port 80 and the development will listen on port 9033. Here are my config server blocks which are located in the same file 生产者将在端口80上侦听,开发将在端口9033上侦听。这是我的配置服务器块,它们位于同一个文件中

server {
  listen 80 default_server;
  server_name mywebsite.com;
  passenger_enabled on;
  passenger_app_env production;
  root /path/to/public/dir;
}

server {
  listen 9033 default_server;
  server_name mywebsite.com;
  passenger_enabled on;
  passenger_app_env development;
  root path/to/public/dir;
  passenger_friendly_error_pages on;
}

The problem lies in that when I try to connect to the website through my browser, regardless of which port I use I always get the version of the website corresponding to the environment specified in the first server block. 问题在于当我尝试通过浏览器连接到网站时,无论我使用哪个端口,我总是得到与第一个服务器块中指定的环境对应的网站版本。 So in the example I gave above, it'd always serve the production version of my website. 所以在我上面给出的例子中,它总是服务于我网站的生产版本。

Why is it that the first server block overrides the second, and how can I make it so that I can access either version of my website without going in a manually changing the config files and reloading nginx? 为什么第一个服务器块会覆盖第二个服务器块,为什么我可以访问我的网站的任何一个版本,而无需手动更改配置文件并重新加载nginx?

UPDATE: 更新:

None of the suggestions were working, even after clearing the browser cache before sending every HTTP request. 即使在发送每个HTTP请求之前清除浏览器缓存之后,这些建议都没有奏效。 I changed my server blocks to the following in the hopes of my server returning different version of the website 我将服务器块更改为以下内容,希望我的服务器返回不同版本的网站

server {
  listen *:80;
  server_name mywebsite.com;
  passenger_enabled on;
  passenger_app_env production;
 root /home/alex/code/m2m/public/;
}


server {
  listen *:80;
  server_name dev.mywebsite.com;
  passenger_enabled on;
  passenger_app_env development;
  root /home/alex/code/m2m/public/;
  passenger_friendly_error_pages on;
}

and then added the following line in my /etc/hosts file 然后在我的/ etc / hosts文件中添加以下行

my.ip.addr.ess    dev.mywebsite.com

But requests to both domains result in only the production version of my website being returned. 但是对两个域的请求导致仅返回我的网站的生产版本。 Note I'm using the default nginx.conf file. 注意我正在使用默认的nginx.conf文件。 Is there a way I can debug my browser (Chrome v40.0.2214.111 (64-bit)) to see if/where my requests are being altered? 有没有办法可以调试我的浏览器(Chrome v40.0.2214.111(64位))以查看我的请求是否/在哪里被更改? I'm thinking the problem lies clientside since the advice the commenters have given me seems like it should work. 我认为问题出在客户端,因为评论者给我的建议似乎应该有效。

And if you try this : 如果你试试这个:

listen *:80;

and

listen *:9033;

This was my recommendation regarding the question that aims nginx config. 这是我关于针对nginx配置的问题的建议。 By putting those listen directives, according to nginx doc, nginx will first match ip:port server blocks and then look at server_name directives in server blocks that matched IP:port. 通过放置那些listen指令,根据nginx doc,nginx将首先匹配ip:port服务器块,然后查看 IP:port 匹配的服务器块中的server_name指令。 So if request containing right 'port' end in the wrong environment this has something to do with either the app or the passenger directives. 因此,如果包含正确“端口”的请求在错误的环境中结束,则这与应用程序或乘客指令有关。

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

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