Use Nginx to access backend applications and solve the ERR_CONTENT_LENGTH_MISMATCH problem

Source: Internet
Author: User
: This article mainly introduces how to access backend applications through Nginx and solve the problem of ERR_CONTENT_LENGTH_MISMATCH. if you are interested in the PHP Tutorial, refer to it. Two problems

1. the date selection function does not work anymore.

2. download a slightly larger file. you can only download half a day.

Error ERR_CONTENT_LENGTH_MISMATCH found during page debugging

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

Do not force refresh. the status code of response is 206

In the response header, the content-length is consistent with the actual length of the target file.

The content length mismatch error is returned.

If you do not use nginx, 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.

I woke up, but I still had no clue. I honestly went to check logs.

/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 nginx as root

2. set the owner of the proxy_temp directory to nginx

3. set the group in the proxy_temp directory to nginx and grant the rwx permission.

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

The preceding section describes how to access backend applications through Nginx and how to solve the ERR_CONTENT_LENGTH_MISMATCH problem, including some content. I hope my friends who are interested in the PHP Tutorial will be helpful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.