【问题标题】:Apache + Mongrel Cluster = Wrong server config!Apache + Mongrel Cluster = 错误的服务器配置!
【发布时间】:2011-03-29 18:42:48
【问题描述】:

我正在尝试让 Ruby on Rails 运行在 Windows 2003 Server 上。我已经安装了 Mongrel 服务和 Apache(以及 RoR 等)。

当我只使用 Mongrel 为应用提供服务时,一切都完美无缺。

所以,现在我要了解 Apache 配置了……显然,我似乎无法做到这一点。当我访问我的页面时,我返回了正确的 HTML,但返回的 Content-Type 设置为 text/plain 而不是 html 或 xhtml...此外,如果我尝试访问其中一个 css 页面,我获得 500 内部服务器错误(以 HTML 形式返回,与 text/plain Content-Type 一起返回)。

这是我的虚拟主机文件(非常感谢任何帮助!):

NameVirtualHost *:8080


#Proxy balancer section (create one for each ruby app cluster)
<Proxy balancer://myapp_cluster>
  Order allow,deny
  Allow from all
  BalancerMember http://rails.localdomain.com:3010
  #BalancerMember http://myapp:3011
</Proxy>




#Virtual host section (create one for each ruby app you need to publish)
<VirtualHost *:8080>
  ServerName rails.localdomain.com
  DocumentRoot c:/www/app/public/

  <Directory c:/www/app/public/ >
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
  </Directory>

  ProxyRequests Off
  ProxyPass / balancer://myapp_cluster
  ProxyPassReverse / balancer://myapp_cluster
  ProxyPreserveHost On
  #SetOutputFilter INFLATE;DEFLATE
  #SetOutputFilter proxy-html

  #log files
  ErrorLog c:/www/log/app_error.log
  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn
  CustomLog c:/www/log/app_access.log combined

  #Rewrite stuff
   RewriteEngine On

  # Check for maintenance file and redirect all requests
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]

  # Rewrite index to check for static
  RewriteRule ^/$ /index.html [QSA] 

  # Rewrite to check for Rails cached page
  RewriteRule ^([^.]+)$ $1.html [QSA]

  # Redirect all non-static requests to cluster
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://myapp_cluster%{REQUEST_URI} [P,QSA,L]


    # Deflate
  #AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
  #BrowserMatch ^Mozilla/4 gzip-only-text/html
  #BrowserMatch ^Mozilla/4\.0[678] no-gzip
  #BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html

</VirtualHost>

【问题讨论】:

  • 哦,我可以在 httpd.conf 文件中将“DefaultType text/plain”更改为“DefaultType text/html”,然后让我的 HTML 页面正确显示,但其他一切仍然很糟糕.....(另外我认为这不是正确的选择)。
  • (当我说“其他一切”时,我的意思是我的 CSS 和 JS 页面等)

标签: ruby-on-rails content-type apache2.2 mongrel-cluster


【解决方案1】:

好的,这是答案的部分。这部分处理 .css 和 .js 文件。显然它与尾随斜杠有关...我必须 删除一些斜杠并 添加其他一些...

已删除:

  DocumentRoot c:/www/app/public

  <Directory c:/www/app/public >

添加:

  ProxyPass / balancer://myapp_cluster/
  ProxyPassReverse / balancer://myapp_cluster/

现在我可以正常提取 .css 和 .js 文件了...

但是:我仍然遇到 Apache 未发送正确标头的问题。在我返回的 HTML 中,我有这个:

但它仍然返回 text/plain(在 httpd.conf 中设置的 DefaultType)。

如果有人有任何想法,请告诉我!!!!!!

谢谢

【讨论】:

  • 我认为是mongrel_cluster没有设置content-type header。
  • 检查rails.localdomain.com:3010 是否返回正确的内容类型。如果它什么都不返回,则 apache 应用默认的。
【解决方案2】:

我强烈推荐一个用于 RoR 的 linux 主机。 Unicorn 和Passenger 是比杂种集群更好的工具。见github blog post about it.

【讨论】:

    猜你喜欢
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2021-09-27
    • 1970-01-01
    • 2013-08-05
    • 2012-02-24
    • 2011-01-01
    相关资源
    最近更新 更多