Help Center> CodeArts Deploy> Best Practices> Using Nginx for Gray Release
Updated on 2024-05-24 GMT+08:00

Using Nginx for Gray Release

Based on the Nginx load balancing mechanism, this practice implements blue-green release and gray release in host deployment scenarios. For more information about Nginx, see Nginx official website.

Application Scenario

When you upgrade a new system, services may be stopped or gray verification may fail. In this practice, you can use the nginx load balancing mechanism for smooth system upgrade without affecting service running.

Solution Architecture

During system upgrade, if the blue-green deployment mode is used, developers bring the server on side A (original blue environment) offline and distribute all access traffic to the server on side B. In this case, the server on side A is upgraded. After the A-side server is upgraded, set the server as the gray test environment. A tester performs gray verification on the A-side server. After the gray verification is complete and the functions are normal, the A-side server (green environment) is officially released, and all traffic is distributed to the A-side server. In this case, the blue-green deployment is complete. If an emergency occurs on the A-side server during service running, perform a blue-green switchover to quickly restore services.

Figure 1 Gray release scheme

If you use canary release, repeat the preceding operations to upgrade the B-side server, complete the gray test, and release the system officially. In this case, the gray release of the new system is complete.

Prerequisites

  • A project is available. If no project is available, create one first.
  • You have the permission to create applications. For details, see Editing Permissions.
  • Target service servers A_test and B_test are available, and application services are running on the servers.
  • A reverse proxy server Gray_release is available.
  • A gray verification host is available. This host represents a gray tester.

Ensure that servers can communicate with each other. For example, add all servers to the same Virtual Private Cloud (VPC).

Procedure

  1. (Optional) Install and start an Nginx node for a reverse proxy server.

    If the Nginx node has been installed and started on your reverse proxy server, skip this step.

    1. Create basic resources.
      1. In the target project, choose Settings > General > Basic Resources. The Host Clusters page is displayed.
      2. Click Create Host Cluster, enter basic information such as the Cluster Name, OS, Use Proxy, Execution Host, and Description, and click Save.
      3. Click Create Target Host, enter the Host Name (for example, A_test, B_test, or Gray_release), IP, Username, Password or Key, and SSH port, and click OK. Repeat the preceding steps to create the three target hosts and verify the connectivity.
    2. Create an application.
      1. Choose CICD > Deploy.
      2. Click Create Application. On the Set Basic Information page, modify the basic information such as Name, Description, and Execution Host as required.
      3. After editing the basic application information, click Next. The deployment template selection page is displayed.
      4. Select Blank Template and click OK. The Deployment Actions tab page is displayed.
    3. Edit the application.
      1. Switch to the Environment Management tab page and add and edit an environment.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to the server, and enter the description.
        • Click Save. The environment is created.
        • Click Import Host. The system automatically filters all clusters that meet the requirements of the current environment. In the dialog box that is displayed, select the target host cluster and click in the Operation column of the target host to import the host to the environment.
      2. Switch to the Deployment Actions tab page. Add and edit the following steps:
        • Add the Install Nginx action and modify the parameters in the following table (Linux is used as an example).
          Table 1 Parameter description

          Parameter

          Description

          Environment

          Select Reverse_proxy_server_group.

          Nginx Version

          Select the target version. Example: nginx-1.14.2.

          Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

        • Add the Start/Stop Nginx action and modify the parameters in the following table (Linux is used as an example).
          Table 2 Parameter description

          Parameter

          Description

          Environment

          Select Reverse_proxy_server_group.

          Operation

          Select Start Nginx.

          Nginx Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

      3. Click Save & Deploy to deploy the application.
    4. Deploy the application.

      After the deployment is complete, the application status bar changes to green and the message Successful is displayed, indicating that the application is successfully deployed.

      If the application status bar turns red and displays Failed, the application fails to be deployed. In this case, click View Solution.

  2. Create and edit application 1 (Gray release of A-side node).

    1. Create an application.
      1. Choose CICD > Deploy.
      2. Click Create Application. On the Set Basic Information page, modify the basic information such as Name, Description, and Execution Host as required.
      3. After editing the basic application information, click Next. The deployment template selection page is displayed.
      4. Select the Deploy a General Application template and click OK.
    2. Edit the application.
      1. Switch to the Environment Management tab page and add and edit an environment.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to the server, and enter the description.
        • Click Save. The environment is created.
        • Click Import Host. The system automatically filters all clusters that meet the requirements of the current environment. In the dialog box that is displayed, select the target host cluster and click in the Operation column of the target host to import the host to the environment.
        • Repeat the preceding steps to create target service server group Target service server group_A-side node and add the A_test server.
      2. Switch to the Parameters tab page and add the following parameters:

      3. Switch to the Deployment Actions tab page. Add and edit the following steps:
        • Add the Start/Stop Nginx action and modify the parameters in the following table (Linux is used as an example).
          Table 3 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Bring_A-side_node_offline.

          Environment

          Select the target environment. Example: Reverse_proxy_server_group.

          Operation

          Specify the operation type Example: Reload configuration file.

          Nginx Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

          Modify configuration file before execution

          Select this parameter.

          Nginx Configuration File Path

          Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

          Configuration File Backup Path

          Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

          Configuration File Content

          Enter content of the new configuration file. See Example code to bring A-side node offline in the appendix.

        • Edit the Download Software Package action and change the parameter values to those listed in the following table (Linux is used as an example).
          Table 4 Parameter description

          Parameter

          Description

          Action Name

          Enter a name Download_software_package_on_A-side_node.

          Source

          Select a source Example: Artifact.

          Environment

          Select the target environment. Example: Target service server group_A-side node.

          Software package

          Select a software package to be deployed in CodeArts Artifact.

          Download Path

          Enter the path for downloading the software package to the target host. Example: /usr/local/.

        • Edit the Run Shell Commands action and modify the parameters as follows (Linux is used as an example):
          Table 5 Parameter description

          Parameter

          Description

          Action Name

          Enter the action name Deploy A-side node.

          Environment

          Select the target environment. Example: Target service server group_A-side node.

          Shell Commands

          Enter the commands to be executed. Example: See Deployment node in the appendix.

        • Add the Start/Stop Nginx action and modify the parameters in the following table (Linux is used as an example).
          Table 6 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Bring A-side node online to gray environment.

          Environment

          Select the target environment. Example: Reverse_proxy_server_group.

          Operation

          Specify the operation type Example: Reload configuration file.

          Nginx Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

          Modify configuration file before execution

          Select this parameter.

          Nginx Configuration File Path

          Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

          Configuration File Backup Path

          Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

          Configuration File Content

          Enter content of the new configuration file. See Example code to bring A-side node online to the gray environment in the appendix.

        • Edit the Health Test via URLs action and modify the parameters as follows (Linux is used as an example):
          Table 7 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Test_A-side_health.

          Environment

          Select the target environment. Example: Target service server group_A-side node.

          Retries

          If a service does not start up when the health test reaches the maximum retries, the service fails this test. Example: 1

          Interval (s)

          Interval between two retries, in seconds. Example: 60

          Test Path

          Used for the health test via URLs. You can add multiple URLs. Example: http://127.0.0.1:3000 (IP address and port number of the application service)

    3. Click Save. The application is created.

  3. Create and edit application 2 (Bring A-side node online).

    1. Create an application.
      1. Click Create Application. On the Set Basic Information page, modify the basic information such as Name, Description, and Execution Host as required.
      2. After editing the basic application information, click Next. The deployment template selection page is displayed.
      3. Select Blank Template and click OK.
    2. Edit the application.
      1. Switch to the Environment Management tab page and add and edit an environment.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to the server, and enter the description.
        • Click Save. The environment is created.
        • Click Import Host. The system automatically filters all clusters that meet the requirements of the current environment. In the dialog box that is displayed, select the target host cluster and click in the Operation column of the target host to import the host to the environment.
      2. Switch to the Deployment Actions tab page. Add and edit the following steps:
        Add the Start/Stop Nginx action and modify the parameters in the following table (Linux is used as an example).
        Table 8 Parameter description

        Parameter

        Description

        Action Name

        Enter a name such as Bring_A-side_node_online.

        Environment

        Select the target environment. Example: Reverse_proxy_server_group.

        Operation

        Specify the operation type Example: Reload configuration file.

        Nginx Installation Path

        Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

        Modify configuration file before execution

        Select this parameter.

        Nginx Configuration File Path

        Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

        Configuration File Backup Path

        Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

        Configuration File Content

        Enter content of the new configuration file. See Example code to bring a node online in the appendix.

    3. Click Save. The application is created.

  4. Clone and edit application 1. Create application 3 (gray release of B-side node).

    1. Clone an application.

      Click and choose Clone.

    2. Edit the application.
      1. Switch to the Environment Management tab page and add and edit an environment.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to the server, and enter the description.
        • Click Save. The environment is created.
        • Click Import Host. The system automatically filters all clusters that meet the requirements of the current environment. In the dialog box that is displayed, select the target host cluster and click in the Operation column of the target host to import the host to the environment.
        • Repeat the preceding steps to create target service server group Target service server group_B-side node and add the B_test server.
      2. Switch to the Deployment Actions tab page. Add and edit the following steps:
        • Edit the Bring A-side node offline action and modify the parameters as follows (Linux is used as an example):
          Table 9 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Bring_B-side_node_offline.

          Environment

          Select the target environment. Example: Reverse_proxy_server_group.

          Operation

          Specify the operation type Example: Reload configuration file.

          Nginx Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

          Modify configuration file before execution

          Select this parameter.

          Nginx Configuration File Path

          Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

          Configuration File Backup Path

          Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

          Configuration File Content

          Enter content of the new configuration file. See Example code to bring B-side node offline in the appendix.

        • Edit the Download software package on A-side node action and change the parameter values to those listed in the following table (Linux is used as an example).
          Table 10 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Download_software_package_on_B-side_node.

          Source

          Select a source Example: Artifact.

          Environment

          Select the target environment. Example: B_group.

          Software package

          Select a software package to be deployed in CodeArts Artifact.

          Download Path

          Enter the path for downloading the software package to the target host. Example: /usr/local/.

        • Edit the Deploy A-side node action and modify the parameters as follows (Linux is used as an example):
          Table 11 Parameter description

          Parameter

          Description

          Action Name

          Enter an action name such as Deploy_B-side_node.

          Environment

          Select the target environment. Example: B_group.

          Shell Commands

          Enter the commands to be executed. Example: See Example code to deploy a node in the appendix.

        • Edit the Bring A-side node online to gray environment action and modify the parameters as follows (Linux is used as an example):
          Table 12 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Bring_B-side_node_online_to_gray_environment.

          Environment

          Select the target environment. Example: Reverse_proxy_server_group.

          Operation

          Specify the operation type Example: Reload configuration file.

          Nginx Installation Path

          Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

          Modify configuration file before execution

          Select this parameter.

          Nginx Configuration File Path

          Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

          Configuration File Backup Path

          Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

          Configuration File Content

          Enter content of the new configuration file. See Example code to bring B-side node online to the gray environment in the appendix.

        • Edit the Test A-side health action and modify the parameters as follows (Linux is used as an example):
          Table 13 Parameter description

          Parameter

          Description

          Action Name

          Enter a name such as Test_B-side_health.

          Environment

          Select the target environment. Example: B_group.

          Retries

          If a service does not start up when the health test reaches the maximum retries, the service fails this test. Example: 1

          Interval (s)

          Interval between two retries, in seconds. Example: 60

          Test Path

          Used for the health test via URLs. You can add multiple URLs. Example: http://127.0.0.1:3000 (IP address and port number of the application service)

    3. Click Save. The application is created.

  5. Clone and edit application 2. Create application 4 (Bring B-side node online).

    1. Clone an application.

      Click and choose Clone.

    2. Edit the application.
      1. Switch to the Environment Management tab page and add and edit an environment.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to the server, and enter the description.
        • Click Save. The environment is created.
        • Click Import Host. The system automatically filters all clusters that meet the requirements of the current environment. In the dialog box that is displayed, select the target host cluster and click in the Operation column of the target host to import the host to the environment.
      2. Switch to the Deployment Actions tab page. Add and edit the following steps:
        Edit the Bring A-side node online action and modify the parameters as follows (Linux is used as an example):
        Table 14 Parameter description

        Parameter

        Description

        Action Name

        Enter a name such as Bring_B-side_node_online.

        Environment

        Select the target environment. Example: Reverse_proxy_server_group.

        Operation

        Specify the operation type Example: Reload configuration file.

        Nginx Installation Path

        Enter the installation path of the Nginx service in the target environment. Example: /usr/local/nginx.

        Modify configuration file before execution

        Select this parameter.

        Nginx Configuration File Path

        Enter the path of the Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx.conf.

        Configuration File Backup Path

        Enter the target path for backing up the original Nginx configuration file on the target host. Example: /usr/local/nginx/conf/nginx_bak.conf.

        Configuration File Content

        Enter content of the new configuration file. See Example code to bring a node online in the appendix.

    3. Click Save. The application is created.

  6. Create and edit a pipeline.

    1. Create a pipeline.
      • Choose CICD > Pipeline.
      • Click Create Pipeline, select a Project, enter a Name, set Pipeline Source to None, and click Next.
      • Select Blank Template and click OK.

    2. Edit job 1 (Gray release of A-side node) in the pipeline stage.
      • Click . In the dialog box that is displayed, set the parameters as follows and click Confirm.
        Table 15 Parameter description

        Parameter

        Description

        Stage Name

        Enter a name such as Gray_release_of A-side_node.

        Always Run

        Select No.

      • Click . In the displayed dialog box, set Entry Type to Automatic and click OK.
      • Click New Job, click the Deploy tab, select Deploy, and click Add. In the dialog box that is displayed, set the parameters as follows and click OK.
        Table 16 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Gray_release_of A-side_node.

        Select Task

        Select Gray_release_of A-side_node.

        Build Task

        Leave it not configured.

    3. Create and edit job 2 (Bring_A-side_node_online) in the pipeline stage.
      • Click and . In the dialog box that is displayed, set the parameters as follows and click Confirm.
        Table 17 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Bring_A-side_node_online.

        Always Run

        Select No.

      • Click . In the displayed dialog box, set Entry Type to Automatic and click OK.
      • Click New Job. In the window that is displayed, click the Normal tab, select Manual Review and click Add, set the parameters as follows, and click OK.
        Table 18 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Gray_release_of A-side_node.

        Reviewer

        Select the service verification personnel.

        Review Mode

        Select Review by all.

        Timeout Processing

        Select Review failed and pipeline terminated.

        Review Duration

        Example: 4 hours.

        Description

        This parameter is optional.

      • Click , click the Deploy tab, select Deploy, and click Add. In the dialog box that is displayed, set the parameters as follows and click OK.
        Table 19 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Bring_A-side_node_online.

        Select Task

        Select Bring_A-side_node_online.

        Build Task

        Leave it not configured.

    4. Edit job 3 (Gray_release_of_B-side_node) in the pipeline stage.
      • Click and . In the dialog box that is displayed, set the parameters as follows and click Confirm.
        Table 20 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Gray_release_of_B-side_node.

        Always Run

        Select No.

      • Click . In the displayed dialog box, set Entry Type to Automatic and click OK.
      • Click New Job, click the Deploy tab, select Deploy, and click Add. In the dialog box that is displayed, set the parameters as follows and click OK.
        Table 21 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Gray_release_of_B-side_node.

        Select Task

        Select Gray_release_of_B-side_node.

        Build Task

        Leave it not configured.

    5. Create and edit job 4 (Bring_B-side_node_online) in the pipeline stage.
      • Click and . In the dialog box that is displayed, set the parameters as follows and click Confirm.
        Table 22 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Bring_B-side_node_online.

        Always Run

        Select No.

      • Click . In the displayed dialog box, set Entry Type to Automatic and click OK.
      • Click New Job. In the window that is displayed, click the Normal tab, select Manual Review and click Add, set the parameters as follows, and click OK.
        Table 23 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Gray_verification_of_B-side_node.

        Reviewer

        Select the service verification personnel.

        Review Mode

        Select Review by all.

        Timeout Processing

        Select Review failed and pipeline terminated.

        Review Duration

        Example: 4 hours.

        Description

        This parameter is optional.

      • Click , click the Deploy tab, select Deploy, and click Add. In the dialog box that is displayed, set the parameters as follows and click OK.
        Table 24 Parameter description

        Parameter

        Description

        Name

        Enter a name such as Bring_B-side_node_online.

        Select Task

        Select Bring_B-side_node_online.

        Build Task

        Leave it not configured.

    6. After the preceding operations are complete, click Save and Run to run pipeline jobs.

  7. Run the pipeline and manually perform gray verification to check whether A-side and B-side nodes are normal.

    When CodeArts Pipeline is executed to bring node A or B online, pipeline execution is suspended. Gray users need to manually verify whether the servers on node A or B in the gray environment are working. Continue to run the pipeline if the servers are working.

    Gray users can run the curl command to check whether the gray environment is normal.

    curl http://IP address of the reverse proxy server:Nginx port

    To check whether the gray user has accessed the target gray environment server, log in to the reverse proxy server and go to the path logs/access.log to view logs.

Appendixes

  • Example code to bring A-side node offline
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$time_local|$remote_addr[$remote_port]|$request|$request_method|$content_length|'
            '$content_type|$http_referer|$host|$http_x_forwarded_for|'
            '$http_true_client_ip|$server_name|$request_uri|$server_addr|$server_port|'
            '$status|$request_time|$upstream_addr|$upstream_response_time|$cookie_domain_tag';
        access_log logs/access.log main; #Access log: storage path and log level
        error_log logs/error.log; #Error log: storage path
        sendfile        on;
        keepalive_timeout  65;
        upstream portal {
            #Enter the IP address and application service port number of host A.
            #server X.X.X.X:X;      #Bring node A offline.
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        upstream portal_test {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        
        server {
            listen       XXX;#Enter the Nginx port number.
            server_name  localhost;
            
            location / {
                set $backend portal;
                set $test portal_test;
                #Enter the IP address of the gray verification host.
                #if ( $remote_addr ~* "X.X.X.X") {
                #    set $backend $test;
                #}
                proxy_pass https://$backend;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
       }
    }
  • Deployment node
    #Obtain the application process ID.
    pid=`ps -ef | grep app_name | grep -v grep | awk '{print $2}'`
    if [ -z "$pid" ];
    then
      echo "[app_name pid is not exist.]"
    else
      echo "app_name pid: $pid "
      #End the process.
      kill -15 $pid
    fi
    #Restart the application. You can run the deployment script or command to start the application.
    #Method 1: Run the deployment script to start the application.
    # sh startup.sh
    #Method 2: Run the command to start the application. nohup is recommended for backend startup.
    # nohup java -jar /usr/local/app/SpringbootDemo.jar &
  • Example code to bring A-side node online to the gray environment
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$time_local|$remote_addr[$remote_port]|$request|$request_method|$content_length|'
            '$content_type|$http_referer|$host|$http_x_forwarded_for|'
            '$http_true_client_ip|$server_name|$request_uri|$server_addr|$server_port|'
            '$status|$request_time|$upstream_addr|$upstream_response_time|$cookie_domain_tag';
        access_log logs/access.log main; #Access log: storage path and log level
        error_log logs/error.log; #Error log: storage path
        sendfile        on;
        keepalive_timeout  65;
        upstream portal {
            #Enter the IP address and application service port number of host A.
            #server X.X.X.X:X;      #Bring node A offline.
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        upstream portal_test {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;       #Gray release of node A
            #Enter the IP address and application service port number of host B.
            #server X.X.X.X:X;
        }
        
        server {
            listen       XXX;#Enter the Nginx port number.
            server_name  localhost;
            
            location / {
                set $backend portal;
                set $test portal_test;
                #Enter the IP address of the gray verification host.
                if ( $remote_addr ~* "X.X.X.X") {
                    set $backend $test;
                }
                proxy_pass https://$backend;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
       }
    }
  • Example code to bring B-side node offline
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$time_local|$remote_addr[$remote_port]|$request|$request_method|$content_length|'
            '$content_type|$http_referer|$host|$http_x_forwarded_for|'
            '$http_true_client_ip|$server_name|$request_uri|$server_addr|$server_port|'
            '$status|$request_time|$upstream_addr|$upstream_response_time|$cookie_domain_tag';
        access_log logs/access.log main; #Access log: storage path and log level
        error_log logs/error.log; #Error log: storage path
        sendfile        on;
        keepalive_timeout  65;
        upstream portal {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;      
            #Enter the IP address and application service port number of host B.
            #server X.X.X.X:X;      #Bring node B offline.
        }
        upstream portal_test {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        
        server {
            listen       XXX;#Enter the Nginx port number.
            server_name  localhost;
            
            location / {
                set $backend portal;
                set $test portal_test;
                #Enter the IP address of the gray verification host.
                #if ( $remote_addr ~* "X.X.X.X") {
                #    set $backend $test;
                #}
                proxy_pass https://$backend;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
       }
    }
  • Example code to bring B-side node online to the gray environment
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$time_local|$remote_addr[$remote_port]|$request|$request_method|$content_length|'
            '$content_type|$http_referer|$host|$http_x_forwarded_for|'
            '$http_true_client_ip|$server_name|$request_uri|$server_addr|$server_port|'
            '$status|$request_time|$upstream_addr|$upstream_response_time|$cookie_domain_tag';
        access_log logs/access.log main; #Access log: storage path and log level
        error_log logs/error.log; #Error log: storage path
        sendfile        on;
        keepalive_timeout  65;
        upstream portal {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;      
            #Enter the IP address and application service port number of host B.
            #server X.X.X.X:X;      #Bring node B offline.
        }
        upstream portal_test {
            #Enter the IP address and application service port number of host A.
            #server X.X.X.X:X;
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;       # Gray release of node B
        }
        
        server {
            listen       XXX;#Enter the Nginx port number.
            server_name  localhost;
            
            location / {
                set $backend portal;
                set $test portal_test;
                #Enter the IP address of the gray verification host.
                if ( $remote_addr ~* "X.X.X.X") {
                    set $backend $test;
                }
                proxy_pass https://$backend;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
       }
    }
  • Example code to bring a node online
    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$time_local|$remote_addr[$remote_port]|$request|$request_method|$content_length|'
            '$content_type|$http_referer|$host|$http_x_forwarded_for|'
            '$http_true_client_ip|$server_name|$request_uri|$server_addr|$server_port|'
            '$status|$request_time|$upstream_addr|$upstream_response_time|$cookie_domain_tag';
        access_log logs/access.log main; #Access log: storage path and log level
        error_log logs/error.log; #Error log: storage path
        sendfile        on;
        keepalive_timeout  65;
        upstream portal {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;      
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        upstream portal_test {
            #Enter the IP address and application service port number of host A.
            server X.X.X.X:X;
            #Enter the IP address and application service port number of host B.
            server X.X.X.X:X;
        }
        
        server {
            listen       XXX;#Enter the Nginx port number.
            server_name  localhost;
            
            location / {
                set $backend portal;
                set $test portal_test;
                #Enter the IP address of the gray verification host.
                #if ( $remote_addr ~* "X.X.X.X") {
                #    set $backend $test;
                #}
                proxy_pass https://$backend;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
       }
    }