欺骗Rails应用程序以为它在其他端口上 [英] Tricking a Rails App to think it's on a different port

查看:69
本文介绍了欺骗Rails应用程序以为它在其他端口上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在端口8080上运行的Rails应用程序,我需要技巧一下才能认为它正在端口80上运行.

I have a Rails app that is running on port 8080 that I need to trick to think it's running on port 80.

我正在端口80上运行Varnish,并将请求转发到端口8080上的nginx,但是当用户尝试使用OmniAuth登录时,Devise gem生成了一个URL以重定向回服务器,它认为它已打开用户将看到的8080端口.

I am running Varnish on port 80 and forwarding requests to nginx on port 8080, but when the user tries to login with OmniAuth and the Devise gem generates a url to redirect back to the server, it thinks its on port 8080 which then the user will see.

是否有任何办法欺骗Rails应用程序将端口硬编码为80(我认为这是一种不好的做法),还是让nginx转发该请求,就像它在端口80上运行一样?

Is there any way to trick the Rails app to hard code the port as 80 (I would think it's a bad practice), or have nginx forward the request as if it's running on port 80?

由于我没有在Rails应用程序上运行nginx代理,所以我想不出一种欺骗端口的方法.

Since I am not running a nginx proxy to the Rails app I can't think of a way to trick the port.

以前有没有人遇到过这个问题,如果需要的话,需要什么样的配置来解决它?

Has anyone ran into this issue before, if so what sort of configuration is needed to fix it?

提前谢谢!

nginx和Varnish都在同一服务器上运行.

Both nginx and Varnish are running on the same server.

推荐答案

我在端口80上使用Varnish,在端口8080上使用nginx进行了相同的设置,而OmniAuth(无Devise)的功能完全相同.我尝试在Varnish中设置X-Forwarded-Port等,在nginx中设置fastcgi_param SERVER_PORT 80;,都没有成功.我设置中的另一部分是乘客"(您没有提到),但是如果您确实在使用乘客",则可以使用:

I have the same setup with Varnish on port 80 and nginx on port 8080 and OmniAuth (no Devise) was doing exactly the same thing. I tried setting X-Forwarded-Port etc in Varnish and fastcgi_param SERVER_PORT 80; in nginx, both without success. The other piece in my setup is Passenger (which you didn't mention) but if you are indeed using Passenger then you can use:

passenger_set_cgi_param SERVER_PORT 80; 

(文档说您可以在http块中进行设置,但是这对我不起作用,我必须将其添加到server块中.)

(The docs say you can set this in an http block but that didn't work for me and I had to add it to the server block.)

http://modrails.com/documentation/Users%20guide%20Nginx .html#passenger_set_cgi_param

这篇关于欺骗Rails应用程序以为它在其他端口上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆