How to deal with the problem that JS can’t fully load under the environment of nginx + Tomcat agent

Time:2020-6-2

Problem scenario: the packaged JS of the VX project is published to the server to report the error, and then the packaged JS is put on the qiniu cloud server. It’s OK to reference the JS in the HTML page. The server was easy to use before, and I don’t know why it’s not working now, so I think: it’s not because it’s related to nginx compression, and then I look for information on the Internet, and finally I find a solution!

Problem scenario

Nginx + tomcat, and the CMS is forwarded by nginx. Such as the common 8080 port to 80, or 80 or 8080 port of other servers. After that, when accessing CMS through port 80, we found that a lot of front-end and back-end JS were half loaded, as shown in the figure error: directly accessing relevant JS, we also found that the content was only half loaded, forced refresh was useless, still only half. But it is no problem to directly access port 80 or 8080 of Tomcat.

Cause of the problem
After the nginx proxy, there will be a corresponding proxy cache area, which is only tens of K by default. Some versions of nginx default settings do not have related processing, which leads to the phenomenon of incomplete loading of some file proxies, in fact, not only JS files. Just because the JS file of the framework is slightly large, similar problems often occur.

Problem solving
stay Nginx.conf Add to

proxy_buffer_size 128k;
proxy_buffers   32 128k;
proxy_busy_buffers_size 128k;

For example:

How to deal with the problem that JS can't fully load under the environment of nginx + Tomcat agent

reference resources:

1. How to deal with the problem that JS can’t fully load under the environment of nginx + Tomcat agent
2. Settings and explanations related to nginx proxy buffer
3、proxy_buffers
4. Gzip configuration parameter description of nginx