Rails应用程序显示空白html

发布于 2024-12-11 19:47:53 字数 1494 浏览 0 评论 0原文

  • Ruby 1.92
  • Rails 3.1.1
  • Nginx 1.1.6
  • Passenger 3.0.7

我的rails应用程序在我的笔记本电脑上运行良好,但在亚马逊服务器上不起作用。我在 chrome 中打开它,浏览器什么也不显示,HTTP 标头如下所示:

HTTP/1.1 200
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 302
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7

如果我运行 rails server,它确实有效,我可以获得正确的 html。 Nginx 无法生成正确的 content-length

nginx 配置

server {
        listen 8000;
        server_name xxxx;
        root /xxx/xxx/public;
        passenger_enabled on;
        rails_env development;


      location = /favicon.ico {
        expires    max;
        add_header Cache-Control public;
      } 


      location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
        access_log off;
        expires max;
       add_header Cache-Control public;
      }

}

http 原始消息返回总长度低于

3496 字节,内容长度错误,因此浏览器会读取其余 html

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7
X-UA-Compatible: IE=Edge
ETag: "12aa68a45bf774886311f827d2149cbe"
Cache-Control: max-age=0, private, must-revalidate
X-Runtime: 0.499998
Server: nginx/1.1.6 + Phusion Passenger 3.0.7 (mod_rails/mod_rack)

<!DOCTYPE html>
<html>
<head>
  <title>xxxx</title>
......
  • Ruby 1.92
  • Rails 3.1.1
  • Nginx 1.1.6
  • Passenger 3.0.7

My rails application works fine on my laptop, but it does not work on amazon server. I open it in chrome, browser display nothing, HTTP header like below:

HTTP/1.1 200
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 302
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7

If I run rails server, it does work, I can get correct html. Nginx cannot generate correct content-length?

nginx config

server {
        listen 8000;
        server_name xxxx;
        root /xxx/xxx/public;
        passenger_enabled on;
        rails_env development;


      location = /favicon.ico {
        expires    max;
        add_header Cache-Control public;
      } 


      location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
        access_log off;
        expires max;
       add_header Cache-Control public;
      }

}

http raw message is below

total 3496 bytes return, content-length is wrong,so browser do read rest html

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7
X-UA-Compatible: IE=Edge
ETag: "12aa68a45bf774886311f827d2149cbe"
Cache-Control: max-age=0, private, must-revalidate
X-Runtime: 0.499998
Server: nginx/1.1.6 + Phusion Passenger 3.0.7 (mod_rails/mod_rack)

<!DOCTYPE html>
<html>
<head>
  <title>xxxx</title>
......

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2024-12-18 19:47:53

HTTP 状态 302 通常是重定向。还有其他标题或正文内容吗?我希望有一个位置标头告诉浏览器重定向到哪里。

A HTTP status of 302 is usually a redirect. Are there any other headers or body content? I'd expect a location header telling the browser where to redirect to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文