繁体   English   中英

Rails开发应用程序无法在不同平台上与nginx proxy_pass一致地提供JS服务

[英]rails development app not serving JS consistently with nginx proxy_pass on different platforms

我会尽量简短地介绍我如何到达这里,但这只是一个3天的旅程。

多年来,我在网络上的某个地方放置了“演示”应用程序,供其他人查看并提供反馈。 最初是在我的笔记本电脑上,开发应用程序在某个高端口上运行,而我的路由器将该端口重定向到我的笔记本电脑上。 我在其他平台(MacMini,RaspberryPI,Linux)上安装了一些应用程序,并在该平台上使用了nginx proxy_pass端口80。 上周,我试图简化流程,并将所有演示放在MacMini上,这就是我遇到了一些无法在jQuery上运行的应用程序的问题,因为在某些演示中找不到或加载了jQuery,通常是那些具有Zurb Foundation的演示。

我不知道应该为这个问题负责,我有五个候选人。

  • 我的nginx配置
  • Rails开发环境
  • 我的JS / CSS清单文件
  • 基础
  • OSX spring / file_watcher问题

为了证明这一点,我在三个平台上运行了一个应用程序(来自git pull的相同代码,相当数量的JS和一些基本的Foundation)。 MacMini运行的是10.13.4(高塞拉,但最近几天我经历了10.12.2和10.12.6)。 运行10.12.6的MacBook Air。 在MacMini的VirtualBox中运行的Rasberrian操作系统(Debian 9)。 [Foundation-rails(6.4.3.0),rails(5.1.6),jquery-rails(4.3.3)]

除了server_name和端口号以外,所有三个基本的nginx配置均相同。 我尝试了各种调整,但是都没有解决我的问题。

server {
  server_name bingo2.mydomain.us;

  location / {
    proxy_redirect     off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://10.0.1.104:8604/;
  }
}

我的JS / CSS清单文件目前在下面。 为了确保我为供应商设置了正确的订单和选项,我已经四处移动东西。 对于CSS文件,我取出了require foundation_and_overides条目,因为它在树中,并且没有任何效果,认为它是从Foundation的旧版本遗留下来的。

// This is a JS manifest file that'll be compiled into application.js, which will include all the files
// listed below.

//
//= require rails-ujs
//= require jquery
//= require foundation
//= require_tree .

$(document).foundation();

/*
 * This is a css manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 *= require_self
 *= require foundation_and_overrides
 *= require_tree .

 */

我最初使应用程序在纯开发环境中运行,但是发现了潜在的错误( https://github.com/rails/rails/issues/26158 ),指出了OSX文件系统问题。 解决方法是删除file_watcher,因此我创建了一个“演示”环境,该环境只是一个开发环境,其中删除了文件观察器gems和config。

我使用rails s -p 8604 -e demo -b 0.0.0.0 -d启动应用程序,然后使用bingo{1,2}.mydomain.us.进入应用程序bingo{1,2}.mydomain.us.

结果是两台Mac均因Web控制台错误而失败

 [Error] Failed to load resource: The network connection was lost. (foundation_and_overrides.self-d1f959e72f9d5d6603cd707629d1e6b8df8a5731363c48252b8b10028591a11a.css, line 0)
 [Error] ReferenceError: Can't find variable: jQuery
  (anonymous function) (foundation.core.self-f3c7f9657e3fa857b22c08af6fe5c52df6f2ad4f5b85268319d47c1be483353d.js:74)
  __webpack_require__ (foundation.core.self-f3c7f9657e3fa857b22c08af6fe5c52df6f2ad4f5b85268319d47c1be483353d.js:21)
  ...

如果我将nginx从方程式中剔除并直接命中本地端口(10.0.1.104:8604),则所有平台都可以使用。 (但是您曾经要求任何人几乎没有技术经验,只能使用端口#!来查看网站上的内容,这会使他们感到困惑,更不用说他们希望将www放入网址中了)

当然,OSX似乎是主要问题,但仅限于proxy_pass。

有人有任何想法或看到我的设置中缺少什么吗? 我想我可以设置临时环境并部署应用程序,但是对于我想做的事情而言,简单的git push和pull似乎非常容易。

关于nginx不提供JS的大多数类似问题仍未得到解答,或者一个简单的错误已得到纠正。

几天没有反应后,我又挖了一点,发现有效果。

Zurb基金会一直存在问题。 我很早以前就放弃了turbo链接。 它只是不能很好地发挥作用,但是除了清单文件中的所有内容之外,所有内容都被删除了,我陷入了一个JavaScript错误,说它找不到基础内容。 在查看$(document).ready$(window).load ,然后将javascript清单更改为:

//= require rails-ujs
//= require jquery
//= require foundation
//= require_tree .

$(window).load(function() {
    //Fires when the page is loaded completely
    $(document).foundation();
});

我猜在进行基础调用时,所有内容均未加载。 $(document).ready并没有解决问题。

这仍然不能回答为什么它可以在Linux而不是MacOSX上运行的原因。

编辑

除非使用chrome导致错误!

net::ERR_CONTENT_LENGTH_MISMATCH

我添加了proxy_buffering off; 到nginx位置。

暂无
暂无

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

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