简体   繁体   English

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

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

I'll try to keep this short on how I got here, but its been about a 3 day journey. 我会尽量简短地介绍我如何到达这里,但这只是一个3天的旅程。

For years put up "Demo" apps somewhere on my network for other people to look at and give me feedback. 多年来,我在网络上的某个地方放置了“演示”应用程序,供其他人查看并提供反馈。 This was initially on my laptop with the development app running on some high port and my router redirecting that port to my laptop. 最初是在我的笔记本电脑上,开发应用程序在某个高端口上运行,而我的路由器将该端口重定向到我的笔记本电脑上。 I have put up a few apps on other platforms (MacMini, RaspberryPI, Linux) and had nginx proxy_pass port 80 to that platform. 我在其他平台(MacMini,RaspberryPI,Linux)上安装了一些应用程序,并在该平台上使用了nginx proxy_pass端口80。 Last week I tried to streamline my process and put all the Demos on the MacMini, thats where I ran into problems with some apps not working in that jQuery was not found or loaded on some demos, usually ones that had Zurb Foundation. 上周,我试图简化流程,并将所有演示放在MacMini上,这就是我遇到了一些无法在jQuery上运行的应用程序的问题,因为在某些演示中找不到或加载了jQuery,通常是那些具有Zurb Foundation的演示。

I can't figure out what is to blame for the problem and I have five candidates. 我不知道应该为这个问题负责,我有五个候选人。

  • My nginx configuration 我的nginx配置
  • Rails development environment Rails开发环境
  • My JS/CSS manifest files 我的JS / CSS清单文件
  • Foundation 基础
  • OSX spring/file_watcher problems OSX spring / file_watcher问题

To document this I have one app (same code from a git pull, fair amount of JS and just a little basic Foundation) running on three platforms. 为了证明这一点,我在三个平台上运行了一个应用程序(来自git pull的相同代码,相当数量的JS和一些基本的Foundation)。 The MacMini is running 10.13.4 (high sierra, but I've gone through 10.12.2 and 10.12.6 in the last few days). MacMini运行的是10.13.4(高塞拉,但最近几天我经历了10.12.2和10.12.6)。 A MacBook Air running 10.12.6. 运行10.12.6的MacBook Air。 A Rasberrian OS (Debian 9) running in VirtualBox on the MacMini. 在MacMini的VirtualBox中运行的Rasberrian操作系统(Debian 9)。 [foundation-rails (6.4.3.0), rails (5.1.6), jquery-rails (4.3.3)] [Foundation-rails(6.4.3.0),rails(5.1.6),jquery-rails(4.3.3)]

The basic nginx config is the same for all three except for the server_name and port number. 除了server_name和端口号以外,所有三个基本的nginx配置均相同。 I've tried various tweaks but none fixed my problem. 我尝试了各种调整,但是都没有解决我的问题。

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/;
  }
}

My JS/CSS manifest files are currently below. 我的JS / CSS清单文件目前在下面。 I've moved stuff around trying to make sure I had the correct order and options set for the vendor. 为了确保我为供应商设置了正确的订单和选项,我已经四处移动东西。 For the CSS file, I took out the require foundation_and_overides entry since it's in the tree and it has no effect, think it was left over from and older version of foundation. 对于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 .

 */

I originally had the apps running in plain development environment, but found a potential bug ( https://github.com/rails/rails/issues/26158 ) that points of an OSX file system problem. 我最初使应用程序在纯开发环境中运行,但是发现了潜在的错误( https://github.com/rails/rails/issues/26158 ),指出了OSX文件系统问题。 A work around to was to remove file_watcher so I created an 'demo' environment which is just a development environment with the file watcher gems and config removed. 解决方法是删除file_watcher,因此我创建了一个“演示”环境,该环境只是一个开发环境,其中删除了文件观察器gems和config。

I start the applications with rails s -p 8604 -e demo -b 0.0.0.0 -d and hit the apps with bingo{1,2}.mydomain.us. 我使用rails s -p 8604 -e demo -b 0.0.0.0 -d启动应用程序,然后使用bingo{1,2}.mydomain.us.进入应用程序bingo{1,2}.mydomain.us.

The results are that both Mac's fail with web console errors 结果是两台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)
  ...

If I take nginx out of the equation and hit the local ports directly (10.0.1.104:8604), all platforms work. 如果我将nginx从方程式中剔除并直接命中本地端口(10.0.1.104:8604),则所有平台都可以使用。 (but have your ever asked anyone little to no technical experience to look at something on a web site using a port #!, it confuses them, let alone they wanting to put www in the url) (但是您曾经要求任何人几乎没有技术经验,只能使用端口#!来查看网站上的内容,这会使他们感到困惑,更不用说他们希望将www放入网址中了)

Certainly OSX seems to be the main problem, but only with proxy_pass. 当然,OSX似乎是主要问题,但仅限于proxy_pass。

Anyone have any ideas or see something missing in my setup? 有人有任何想法或看到我的设置中缺少什么吗? I guess I could just set up staging environments and deploy the apps, but a simple git push and pull seems so much easier for what I wanted to do. 我想我可以设置临时环境并部署应用程序,但是对于我想做的事情而言,简单的git push和pull似乎非常容易。

Most similar questions about nginx not serving JS remain unanswered or a simple mistake being corrected. 关于nginx不提供JS的大多数类似问题仍未得到解答,或者一个简单的错误已得到纠正。

After a couple days with no response, I dug a little more and found something that works. 几天没有反应后,我又挖了一点,发现有效果。

Zurb Foundation has always presented problems. Zurb基金会一直存在问题。 I gave up on turbo links long ago. 我很早以前就放弃了turbo链接。 It just does not play well with it, but getting rid of everything in the manifest files except what was required, I got down to one javascript error saying it could not find foundations stuff. 它只是不能很好地发挥作用,但是除了清单文件中的所有内容之外,所有内容都被删除了,我陷入了一个JavaScript错误,说它找不到基础内容。 After looking at $(document).ready versus $(window).load , I then changed the javascript manifest to: 在查看$(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();
});

I guess everything was not loaded when the foundation call was made. 我猜在进行基础调用时,所有内容均未加载。 `$(document).ready just was not doing the trick. $(document).ready并没有解决问题。

This still does not answer why it works on linux and not MacOSX. 这仍然不能回答为什么它可以在Linux而不是MacOSX上运行的原因。

EDIT 编辑

Except that caused an error using chrome! 除非使用chrome导致错误!

net::ERR_CONTENT_LENGTH_MISMATCH

I added proxy_buffering off; 我添加了proxy_buffering off; to the nginx location. 到nginx位置。

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

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