Two problems encountered in Nginx server application

Source: Internet
Author: User
Tags nginx server

1 "The first is the 413 error!

1 client_max_body_size2 context:http, server, location3 It is the maximum size of a client request body. If this size is exceeded, Nginx4Returns a413 Request entity too large HTTP error. This setting is particularly5ImportantifYou is going to allow users to upload files to your server over HTTP.6 syntax:size Value7Default value:1m

This error means that the amount of data requested by the client is too large. Nginx configuration, if there is no specific content to specify this option, the default is the size of 1m. However, for HTTP requests that are too large for the request, you need to configure the appropriate configuration with a larger body size for your Web site.

The configuration of this parameter is suitable for the location of Http,server,location three places can be.

2 "504 Gateway time-out error

This error is related to the time configuration. People may have this scenario, such as an HTTP request to the backend service, the backend service will take longer to give the front-end response, this time to consider whether there will be such a 504 error.

My application is in the CMS system we developed, the front-end request background to perform publishing 13,000 posts. This will take some time, our system, 13000 pieces of article, about 3 minutes.

Our server architecture is simple, the front-end Nginx is responsible for static resource response, Nginx as a reverse proxy to achieve load balancing (tomcat as a back-end server), processing back-end dynamic HTTP requests, such as the publishing page of this backend service HTTP request is also in it.

This error, corresponding to the Nginx error log, will see the following content:

1  ./ ,/ to  -: -: .[ERROR]31490#0: *48123Upstream timed out ( the: Connection timed out) whileReading response header from upstream, client:10.90.9.20, Server:localhost, Request:"get/cms/page/articlecenter/deployeeall?type=41 http/1.1", Upstream:"http://10.130.202.135:8080/CMS/page/articleCenter/deployeeAll?type=41", Host:"10.130.202.136", referrer:"Http://10.130.202.136/CMS/page/pageTreeMgmt"

So, how to solve this kind of mistake? Let's take a look at Nginx server configuration documentation!

for write for backend communications 

This error, because the above two timeout time is not set, the default value is smaller, 60s, here, we will modify its relatively large, has changed to 3000.

The solution of the above two problems is very simple, the configuration of the modified content is also attached here as a reference bar!

1 http {2 include mime.types;3Default_type application/octet-stream;4 5#log_format Main'$remote _addr-$remote _user [$time _local] "$request"'6#'$status $body _bytes_sent "$http _referer"'7#'"$http _user_agent" "$http _x_forwarded_for "';8 9#access_log logs/Access.log main;Ten  One sendfile on; A #tcp_nopush on; -  -#keepalive_timeout0; theKeepalive_timeout +; -#gzipon ; -  - upstream CMS { +Serverxx.xx.xx.xx:8080; -     } + client_max_body_size 10M; #解决第一个问题的配置 A  at server { -Listen the; - server_name localhost; -         #下面两行是解决第二个错误的配置 -         proxy_send_timeout; -         proxy_read_timeout; inLocation/cms{ -  toProxy_pass http://CMS; + proxy_set_header Host $host: $server _port; - proxy_set_header remote_addr $remote _addr; theProxy_set_header x-real-IP $remote _addr; *Proxy_set_header x-forwarded-For $proxy _add_x_forwarded_for; $           }Panax Notoginseng  -Location/Resource { theRoot html/Tk_root; + Allow all ; A           } the       } +}

Two problems encountered in Nginx server application

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.