Use Nginx to access backend applications, solve the ERR_CONTENT_LENGTH_MISMATCH problem, and nginx front-end apache backend
Two problems are encountered. 1. Date selection does not work. 2. download a file that is slightly larger. You can only download the half page. The error ERR_CONTENT_LENGTH_MISMATCH is found.
System: CentOS, Nginx, proxy to backend tomcat
Cause: nginx caches large files to the proxy_temp directory. However, nginx does not have the read/write permission on this directory.
Solution Process:
Page debugging, throwing an error: net: ERR_CONTENT_LENGTH_MISMATCH in chrome. cache or force refresh. the status code of response is 200, not force refresh, And the status code of response is 206 response header, if the length of content-length is the same as the actual length of the target file, the above content length mismatch Error occurs. If nginx is not used, you can directly access tomcat without this error. The system function is normal.
I found a post for various searches. The problem description is very similar. It is mentioned that nginx gzip is compressed. Because nginx has prepared for File compression, it processes the data stream according to the compressed length, however, the data passed through the proxy is not actually compressed, and the connection is closed if it is not completed. From the log, many org. apache. catalina. connector. ClientAbortException occurs on the tomcat side, which matches the previous ERRO_CONTENT_LENGTH_MISMATCH request.
Start to learn about nginx gzip configuration (prepare another note)
The problem is not solved. Go to bed first and wake up.
When I woke up, I still had no clue. I honestly checked log/var/log/nginx/error. log.
Aha, the problem is as follows:
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:...
Proxy_temp directory. The owner is root and rwx. Other users do not have the permission. Nginx runs as an nginx user and has no permissions!
Solution:1. Run nginx2. as the root user. Set the owner of the proxy_temp directory to nginx3. set the group of the proxy_temp directory to nginx and grant rwx permissions. 4. Disable cache.
If you don't want to use root to run nginx, select method 3 to let the system work first.
Legacy problems:1. Why is the owner of the proxy_temp directory root at first? Should it be root? 2. After method 3 is selected, multiple caches are generated for the same file. This is unreasonable. Why? 3. Do we need cache for this situation? It is more reasonable to disable the cache.
> To be continued
Huang He