Home > Backend Development > PHP Tutorial > Accessing back-end applications through Nginx, solving the ERR_CONTENT_LENGTH_MISMATCH problem

Accessing back-end applications through Nginx, solving the ERR_CONTENT_LENGTH_MISMATCH problem

WBOY
Release: 2016-08-08 09:23:30
Original
5279 people have browsed it

Encountered two problems

1. The date selection function does not work

2. When downloading a slightly larger file, you can only download a small half of the page

Debugging found an ERR_CONTENT_LENGTH_MISMATCH error

System: Cent OS, Nginx, proxy to the backend tomcat

Cause: nginx will cache large files to pr oxy_temp directory, however for this The directory does not have read and write permissions

Solution process:

Page debugging, throwing error: net::ERR_CONTENT_ LENGTH_MISMATCH

at Under chrome, please cache or force refresh. The status code of the response is 200. No forced refresh. The status code of the response is 206. The actual length is consistent

will cause the above content length mismatch error

If you don’t access tomcat directly through nginx, without this error, the system functions normally.

After various searches, I found a post first. The description of the problem is very similar. It mentions nginx gzip compression. Since nginx prepares the file for compression, it processes the data stream according to the compressed length. , but the data passed through the proxy is not actually compressed, and ngnix closes the connection before the transmission is completed.

Judging from the log, there are indeed many org.apache.catalina.connector.ClientAbortExceptions on tomcat, which match the previous requests with ERRO_CONTENT_LENGTH_MISMATCH.

Start learning the configuration of nginx gzip (preparing to make another note)

The problem is not solved, go to bed first, and continue working on it when you wake up

I woke up, but still had no clue, so I checked the log honestly

/var/log/nginx/error.log

Aha, the problem is here:

2015/05/30 00:11:53 [crit] 8808#0: *60 open() "/var/cache/nginx/proxy_temp/2/01/0000000012" failed (13: Permission denied) while reading upstream, client:...
Copy after login

proxy_temp directory, the owner is root, rwx permissions, other users have no permissions.

nginx runs as the nginx user without permissions, boom!


Solution:

1. Run nginx as root

2. Set the owner of the proxy_temp directory to nginx

3. Set the group of the proxy_temp directory to nginx and grant rwx permissions

4. Disable cache

I don’t want to use root to run nginx, so I chose method 3 and let the system work first

Remaining questions:

1. Why is the owner of the proxy_temp directory root in the first place? Should it be root?

2. After choosing method 3, I found that multiple caches will be generated for the same file. This is unreasonable. Why is this happening?

3. In our case, is cache needed? Is it a more reasonable choice to disable cache

>> 5-05-30 The above introduces how to access back-end applications through Nginx and solve the ERR_CONTENT_LENGTH_MISMATCH problem, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template