Nginx work a scene
Nginx is one of the most popular HTTP server in our company plays a pivotal role, as one of our company's core component is an integral part of the entire access link, but, Nginx components, modules , many versions, so how to manage Nginx will be crucial.
Before we get started, let's take a look at the scene Nginx work:
"1" static resources of the web server
"2" http, smtp, pop3 protocols such as reverse proxy server
"3" cache acceleration and load balancing
We mainly used the Nginx second function, namely reverse proxy server, Nginx our services through a proxy to Real Server, both to ensure the safety of the Real Server, but also played a load balancing of traffic.
Two Nginx processing flow problem
1 Nginx own investigation
If there is a problem, first check whether the time is nginx own factors of service is not available,
"1" check Nginx service is started,
sudo lsof -P -n -i :80 -i :443 | grep LISTEN
ps aux | grep nginx
"2" if the service dawdle out, first try to start the service
sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
"3" if 2 is successful, the corresponding access service, to see if normal,
If the two fail, you need to check nginx configuration files, as well as various functional modules, to be more precise positioning, we need to turn on debug mode and then execute:
nginx –t
tail –f /data/log/nginx/error.log
"4" to see the parameters nginx compile time, see if it is some function module is not compiled in.
nginx -V
2 external factors investigation
Here are the main Nginx outside interference issues outside of the ring causes the service is not available, such as Navigator, APIRouter and so on.
"1" if the new hair configuration to ensure Navigator releases into force
"2" binding LB external network address of the nginx clusters corresponding to local hosts, access to observe service is available
"3" checking DNS records
If "2" is available, then before the Nginx part of the problem, this time to be resolved using the dig tool to check to see if correct. If you are parsing error correction can be.
dig domain
dig -t A + trace domain name
3 having returned to the client determines the status point of failure
"1" 3xx class response code
3xx class status code, the response status code is typically based redirection, where 301 is the permanent redirect, 302 temporary redirection, 304 represents a response from the cache, if an access domain, the problem appears to jump, it is necessary to check nginx configuration, rewrite the rules to see whether it is reasonable, whether the location priority issues arise.
"2" 4xx class response code
4xx class status code indicates that the client general error classes,
If the 400 error is usually expressed client sent an invalid request. If the request is not a http1.1 host domain, server should send a 400 status code to the client segments, it indicates that the server can not handle the request.
403 If an error occurs, you will be prompted Forbidden, expressed disable access to, these reasons generally speaking there are two possibilities, one: The client requests resources to do a black and white lists, or special resources (for example: status page );two is:
404 If an error occurs, it will return to NOT Found state, produce this error, the general is the wrong user initiates the request, the requested resource does not exist. Nginx need to access the directory, but autoindex option is turned off.
"3" class 5xx response code
500 class response code usually indicates a problem with the server, there may be a problem nginx addition, it may also be the back-end Real Server fails.
502 error is returned Bad Gateway, and Gateway error, in this case, may be related to the type of cgi
504 error will return Time Out, usually expressed as a proxy When nginx not receive a timely request from the upstream server, in which case either the back-end service can not process the request nginx forward, resulting in a request timed out, or is in addition to the back-end server failure such as service stops unexpectedly ...
Three common status codes
Status code information retrieval address: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status
status code | meaning | Explanation |
---|---|---|
status code | meaning | Explanation |
200 | OK | Normal requests processed |
301 | Moved Permanently | Permanent redirect |
302 | Found | Temporary Redirect |
304 | Not Modified | Condition requests, the resource is not modified |
400 | Bad Request | Request message syntax error or parameter error |
401 | Unauthorized | Required by HTTP authentication, or authentication failed |
403 | Forbidden | The requested resource is denied (eg: blacklist state detection resources, etc.) |
404 | Not Found | Unable to find the requested resource |
409 | Conflict | It represents a request with the current status of the server conflict; clashes are most likely to occur in PUT response to a request. For example, when uploading files than the version already exists on the server is older, resulting in a version conflict, then you may receive a response with status code 409. |
500 | Internal Server Error | Web application server failure or malfunction |
502 | Bad Gateway |
The proxy server, the response received from the upstream to the server is invalid |
503 | Service Unavailable | Server is overloaded or down for maintenance |
504 | Gateway Timeout |
Proxy server can not get the desired response within a specified time |
505 | HTTP Version Not Supported |
It indicates that the server does not support the HTTP version used in the request |