在生产中部署 Rails 3 应用程序后,我注意到路径并不总是显示在浏览器窗口中。例如,访问登录或 my_profile 链接仍然只会显示 http://my_app.com 而不是预期的 http://my_app.com/login 或 http://my_app.com/my_profile。观点确实发生了变化并且发挥了作用。我还可以看到数据库被命中以及从日志中呈现的视图(这让我相信这不是一个简单的浏览器缓存问题)。直接访问 http://my_app.com/login 可以,但是,使用应用程序中的链接需要我到预期的位置,同时保留显示的登录网址。我在几个浏览器(firefox、opera 和 chrome)中尝试过,并得到了相同的行为。该应用程序部署在 nginx+passenger 和后来的 nginx+thin cluster 下。我的问题是,发生了什么事?是nginx设置还是我的生产环境设置?我不知道从哪里开始。
运行curl -v my_app.com 显示
* About to connect() to my_app.com port 80 (#0)
* 正在尝试 xx.xx.xx.xx...已连接
* 连接到 my_app.com (xx.xx.xx.xx) 端口 80 (#0)
<代码>> GET / HTTP/1.1
<代码>>用户代理:curl/7.21.1 (x86_64-apple-darwin10.4.0) libcurl/7.21.1 OpenSSL/1.0.0a zlib/1.2.5 libidn/1.19
<代码>>主机:my_app.com
<代码>>接受:*/*
>
* HTTP 1.0,假设正文后关闭
<代码>< HTTP/1.0 200 好的
<代码><设置 Cookie:ARPT=PKKIKIS10.0.81.64CKILJ;路径=/
<代码><内容类型:text/html;字符集=utf-8
<代码><状态:200
<代码>< X-Powered-By:Phusion Passenger (mod_rails/mod_rack) 2.2.5
<代码>< ETag:“fce6dec3543058bec16175466020a906”
<代码>< X-运行时:7
<代码><内容长度:787
<代码><缓存控制:私有,max-age=0,必须重新验证
<代码><服务器:nginx/0.7.62 + Phusion Passenger 2.2.4 (mod_rails/mod_rack)
<代码>< P3P:CP =“IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT”
<代码>< X-Cache:来自 server.com 的 MISS
<代码><通过:1.0 server.com:8080
<代码><连接:关闭
http://my_app.com/
<框架名称=“DDIRECTXYZZY2”滚动=“自动”src=“http://xxx.xx.xxx.xxx”noresize>
<框架名称=“DDIRECTXYZZY”滚动=“no”noresize>
< br>
请点击此处查看无框版本
上。
所以这显然是一个问题。整个事情都被 DNS 重定向框定了?设置不是 Phusion Passenger + nginx。原来是,现在是thin + nginx。另外,当直接访问应用程序的 IP 地址时,一切都很好。当我访问域名时,我得到的是加框版本。仅 IP 地址的 curl -v
响应看起来也很正常(就像加载整个页面一样)。
After deploying my rails 3 app in production I noticed that paths are not always shown in the browser window. For example going to login or my_profile links would still only show http://my_app.com instead of expected http://my_app.com/login or http://my_app.com/my_profile. The views did change and were functional. I could also see the database being hit and views being rendered from the logs (which led me to believe it was not a simple browser cache issue). Going directly to http://my_app.com/login worked, however, using the links in the app would take me to the expected place while leaving the login url displayed. I tried it in several browsers (firefox, opera and chrome) and got the same behavior. The app was deployed under nginx + passenger and later nginx + thin cluster. My question is, whats going on? Could it be nginx settings or my production environment settings? I am not sure where to start.
Running curl -v my_app.com shows
* About to connect() to my_app.com port 80 (#0)
* Trying xx.xx.xx.xx... connected
* Connected to my_app.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.21.1 (x86_64-apple-darwin10.4.0) libcurl/7.21.1 OpenSSL/1.0.0a
zlib/1.2.5 libidn/1.19
> Host: my_app.com
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Set-Cookie: ARPT=PKKIKIS10.0.81.64CKILJ; path=/
< Content-Type: text/html; charset=utf-8
< Status: 200
< X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.5
< ETag: "fce6dec3543058bec16175466020a906"
< X-Runtime: 7
< Content-Length: 787
< Cache-Control: private, max-age=0, must-revalidate
< Server: nginx/0.7.62 + Phusion Passenger 2.2.4 (mod_rails/mod_rack)
< P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
< X-Cache: MISS from server.com
< Via: 1.0 server.com:8080
< Connection: close
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>http://my_app.com/</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta name="generator" content="Hover Redirect Service">
</head>
<frameset framespacing="0" rows="100%,*" cols="100%" frameborder="no" border="0">
<frame name="DDIRECTXYZZY2" scrolling="auto" src="http://xxx.xx.xxx.xxx" noresize>
<frame name="DDIRECTXYZZY" scrolling="no" noresize>
<noframes>
<h1><a href="http://xxx.xx.xxx.xxx">http://my_app.com/</a></h1>
<p>Please <a href="http://xxx.xx.xxx.xxx">click here</a> to view the non-framed versi
on.</p>
</noframes>
</frameset>
</html>
So that is clearly a problem. The whole thing gets framed by the DNS redirect? The setup is not Phusion Passenger + nginx. It was originally, but now its thin + nginx. Also, when going directly to ip address of the app, things are just fine. When going to the domain name, I get the framed version. curl -v
response of just the ip address also looks normal (like its loading the entire page).
发布评论
评论(2)
问题几乎肯定出在你的框架上。内部框架正在加载正确的内容,但因为(大概)您没有在链接(或其他任何内容)中定位“顶部”,所以浏览器仍然显示最外层框架的 URL。
定位框架:http://www.w3.org/TR/ html4/present/frames.html#h-16.3
如果您根本不希望在响应中看到框架,那么它们很可能是劣质“DNS”服务的责任。获取指向您服务器的真实 DNS 地址,您就可以唱歌了。
The problem is almost certainly your frames. The inner frame is loading the correct content but because you're (presumably) not targeting 'top' in your links (or whatever it is), the browser is still showing the URL of the outermost frame.
Targeting frames: http://www.w3.org/TR/html4/present/frames.html#h-16.3
If you were not expecting to see frames in your response at all then it's likely they're the responsibility of a shoddy "DNS" service. Get a real DNS address pointed to your server and you'll be singing.
您是否尝试使用另一台客户端计算机进行测试?如果我按照你的解释,那就是你还没有研究过的一种选择。
您可以将您的 nginx 配置发送给我们吗?
Did you try using another client computer to do your tests? If I follow your explication, that's one option you haven't investigated.
Can you send us your nginx configuration maybe?