All Products
Search
Document Center

:When SLB is used, site access is normal but site exception is health check

Last Updated:Nov 26, 2020

Question

The SLB instance uses HTTP listeners and is configured with the HEAD method for health check. An exception is displayed in the health check when the business site can be normally accessed. To simulate the health check, you can use the HEAD method and run nc commands to test the status of the business site. An example command is as follows:

echo -e "HEAD /test.html HTTP/1.0\r\n\r\n" | nc -t www.example.com 80

Note: the test.html and www.example.com in the command are only examples. The actual situation is used at the site.

The HTTP status code 404 is returned as follows:

For comparison, run the curl command to test the status of the business site.

curl -I http://www.example.com/test.html

The following figure shows that the value of the HTTP status code is 200, which is normal and is different from that of the HEAD method and the nc command.

The main problems mentioned above are as follows:

  • Problem 1
    The service site can be normally accessed why the SLB health check and simulation test in HEAD method and nc commands to display the site exception but curl command displays the site is running normally?
  • Problem 2
    The HTTP status code returned by the service site is 404. Why is health check abnormal?

Cause

The causes of the above problems are as follows:

  • Problem 1
    The reasons for different results are as follows:
    • curl command
      The curl command is consistent with the result returned by a browser. A resource file under the requested domain is accessed, that is, the test.html file under www.example.com domain name.
    • The health check of the SLB instance.
      If no health check domain name is configured for the SLB instance, the request domain name for health check is the IP address of the backend server, such as 192.0.2.1. Files are returned. Therefore, HTTP 404 status code is returned.
      Note: The following takes the default configuration of Nginx as an example. The default configuration of Nginx contains the default website.

    • HEAD method and simulation test of nc commands
      The HEAD method is itself fine, but the nc command forwards the request to the IP address corresponding to the domain name, which is the same as the SLB instance's health check. The final request will go to the default site of the Web server, so the HTTP 404 status code is returned.

  • Problem 2
    By default, the health check configurations of the SLB instance use http_2xx and http_3xx as the normal status code. All other status code are identified as abnormal status code. HTTP 404 belongs to http_4xx, so it is health check determined as a site exception.

Answer

This topic provides different solutions for different issues.

  • Problem 1
    Regarding this problem, there are two solutions, you can choose according to the actual situation:
    • Improve the health check configuration of an SLB instance.
      You can log on to the SLB instance of health check configuration perfect health check path and health check domain options. Herein, for example, you can set the health check domain for www.example.com, health check path for /test.html. For more information about how to configure health check and these two options, see configure health check.

    • Disable the default site for Web servers
      You can modify the configuration file of the Web server to disable the default site. Configuration methods vary according to the Web server. The following procedure uses an Nginx server as an example.
      1. Remotely log on to the server where Nginx is installed.
      2. Locate the main configuration file for Nginx. The default path is /etc/nginx/nginx.conf. If Nginx is installed by using the source code, you can confirm the path of the Nginx master configuration file.
      3. Edit the main configuration file of Nginx, find the server configuration segment marked as default_server, comment out this code segment with a number sign (#), and exit and save the file.

      4. Run the following command to confirm that the updated configuration file is normal:
        nginx -t
        If the system returns an exception, fix it as prompted until the system returns the following.
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful
      5. Run the following command to reload the Nginx configuration file:
        nginx -s reload
      6. Check the status of the health check instance again.


  • Problem 2
    You can select the HTTP health check that are in the normal status in the status code configuration of your SLB instance based on your business needs. If you do not think HTTP 404 is a site exception, you can select http_4xx as the normal status code. For more information about how to Health Check an SLB instance, see configure health check.

Application scope

  • SLB