Help Center/ CodeArts Deploy/ Best Practices/ Using Nginx for Gray Release
Updated on 2025-05-27 GMT+08:00

Using Nginx for Gray Release

Application Scenario

When you upgrade to 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

When upgrading the system using blue-green deployment, perform the following operations:

  1. Bring server A (blue environment, carrying the current workloads) offline and distribute all access traffic to server B. Upgrade server A.
  2. After the server A is upgraded, set it as the gray test environment and let testers perform gray verification on it.
  3. After the gray verification is complete and the functions become normal, release server A (green environment) and move all traffic from B to it. Now, the blue-green deployment is complete.
  4. If an emergency occurs on the server A during service running, perform a blue-green switchover to quickly restore services.
Figure 1 Gray release scheme

If you use canary release, upgrade server B by referring to operations described in blue-green deployment. Complete the gray test on it and release it to complete the gray release.

Prerequisites

  • A project is available. If there is no project, Project Managers: Creating and Configuring Projects first.
  • You have the permissions 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. To ensure it, you can add all servers to the same virtual private cloud (VPC).

Process

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.

Figure 2 Process flowchart
  1. (Optional) Install and start an Nginx node for the 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. Go to the CodeArts homepage and click the target project name to access the project.
      2. Choose Settings > General > Basic Resources to access the Host Clusters page.

        Alternatively, choose CICD > Deploy > Basic Resources to access the Host Clusters page.

      3. Click Create Host Cluster, enter basic information such as the Cluster Name, OS, Proxy, Execution Resource Pool, and Description, and click Save.
      4. Create three hosts (A_test, B_test, and Gray_release) and verify their connectivity. Specifically, click Add Host, select Adding IP, enter the host name, IP, Username, Password or Key, and SSH Port, and click OK. For details about connectivity verification, see Hosts.

    2. Create an application.
      1. Choose CICD > Deploy.
      2. Click Create Application. On the Basic Information page, specify the Name, Description, and Execution Resource Pool 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. Create an environment and edit it.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to each server, and enter the description information.
        • 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 displayed dialog box, 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 the following actions and edit them.
        • Add the Install Nginx action and modify the parameters in the following table (Linux is used as an example).
          Table 1 Parameter description

          Parameter

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Environment

          Yes

          Select Reverse_proxy_server_group.

          Nginx Version

          Yes

          Select a target version. Example: nginx-1.14.2.

          Installation Path

          Yes

          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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Environment

          Yes

          Select Reverse_proxy_server_group.

          Operation

          Yes

          Select Start Nginx.

          Nginx Installation Path

          Yes

          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.

      If the application status bar turns green and displays Successful, the application is deployed successfully.

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

      For more deployment problems, see Creating an Application.

  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 Basic Information page, specify the Name, Description, and Execution Resource Pool 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. Create an environment and edit it.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to each server, and enter the description information.
        • 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 displayed dialog box, 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_A-side node and add the A_test server.
      2. Switch to the Parameters tab page. Add the following parameters:

      3. Switch to the Deployment Actions tab page. Add the following actions and edit them.
        • 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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Enter a name such as Bring_A-side_node_offline.

          Environment

          Yes

          Select a target environment. Example: Reverse_proxy_server_group.

          Operation

          Yes

          Specify an operation type. Example: Reload configuration file.

          Nginx Installation Path

          Yes

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

          Modify configuration file before execution

          No

          Select this option for this example.

          Nginx Configuration File Path

          Yes

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

          Configuration File Backup Path

          No

          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

          Yes

          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 modify the parameters in the following table (Linux is used as an example).
          Table 4 Parameter description

          Parameter

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Download_software_package_on_A-side_node.

          Source

          Yes

          Select a source. Example: Artifact.

          Environment

          Yes

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

          Software Package

          Yes

          Select a software package to be deployed in CodeArts Artifact.

          Download Path

          Yes

          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 in the following table (Linux is used as an example).
          Table 5 Parameter description

          Parameter

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Deploy A-side node.

          Environment

          Yes

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

          Shell Commands

          Yes

          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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Bring A-side node online to gray environment.

          Environment

          Yes

          Select a target environment. Example: Reverse_proxy_server_group.

          Operation

          Yes

          Specify an operation type. Example: Reload configuration file.

          Nginx Installation Path

          Yes

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

          Modify configuration file before execution

          No

          Select this option for this example.

          Nginx Configuration File Path

          Yes

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

          Configuration File Backup Path

          No

          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

          Yes

          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 in the following figure (Linux is used as an example):
          Table 7 Parameter description

          Parameter

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Enter a name such as Test_A-side_health.

          Environment

          Yes

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

          Retries

          Yes

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

          Interval (s)

          Yes

          Interval between two retries, in seconds. Example: 60

          Test Path

          Yes

          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 Basic Information page, specify the Name, Description, and Execution Resource Pool 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. Create an environment and edit it.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to each server, and enter the description information.
        • 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 displayed dialog box, 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 the following actions and edit them.
        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

        Mandatory

        Description

        Action Name

        Yes

        Enter a customized action name displayed in the deployment actions.

        Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

        Example: Bring_A-side_node_online.

        Environment

        Yes

        Select a target environment. Example: Reverse_proxy_server_group.

        Operation

        Yes

        Specify an operation type. Example: Reload configuration file.

        Nginx Installation Path

        Yes

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

        Modify configuration file before execution

        No

        Select this option for this example.

        Nginx Configuration File Path

        Yes

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

        Configuration File Backup Path

        No

        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

        Yes

        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. Create an environment and edit it.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to each server, and enter the description information.
        • 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 displayed dialog box, 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_B-side node and add the B_test server.
      2. Switch to the Deployment Actions tab page. Add the following actions and edit them.
        • 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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Bring_B-side_node_offline.

          Environment

          Yes

          Select a target environment. Example: Reverse_proxy_server_group.

          Operation

          Yes

          Specify an operation type. Example: Reload configuration file.

          Nginx Installation Path

          Yes

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

          Modify configuration file before execution

          No

          Select this option for this example.

          Nginx Configuration File Path

          Yes

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

          Configuration File Backup Path

          No

          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

          Yes

          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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Download_software_package_on_B-side_node.

          Source

          Yes

          Select a source. Example: Artifact.

          Environment

          Yes

          Select a target environment. Example: B_group.

          Software Package

          Yes

          Select a software package to be deployed in CodeArts Artifact.

          Download Path

          Yes

          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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Deploy_B-side_node.

          Environment

          Yes

          Select a target environment. Example: B_group.

          Shell Commands

          Yes

          Enter the commands to be executed. Example: See Deployment 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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Example: Bring_B-side_node_online_to_gray_environment.

          Environment

          Yes

          Select a target environment. Example: Reverse_proxy_server_group.

          Operation

          Yes

          Specify an operation type. Example: Reload configuration file.

          Nginx Installation Path

          Yes

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

          Modify configuration file before execution

          No

          Select this option for this example.

          Nginx Configuration File Path

          Yes

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

          Configuration File Backup Path

          No

          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

          Yes

          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

          Mandatory

          Description

          Action Name

          Yes

          Enter a customized action name displayed in the deployment actions.

          Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

          Enter a name such as Test_B-side_health.

          Environment

          Yes

          Select a target environment. Example: B_group.

          Retries

          Yes

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

          Interval (s)

          Yes

          Interval between two retries, in seconds. Example: 60

          Test Path

          Yes

          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. Create an environment and edit it.
        • Click Create Environment, enter the environment name, for example, Reverse_proxy_server_group, select the OS corresponding to each server, and enter the description information.
        • 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 displayed dialog box, 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 the following actions and edit them.
        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

        Mandatory

        Description

        Action Name

        Yes

        Enter a customized action name displayed in the deployment actions.

        Enter 1 to 128 characters. Do not start or end with a space. Use letters, digits, spaces, and these special characters: -_,;:./()

        Example: Bring_B-side_node_online.

        Environment

        Yes

        Select a target environment. Example: Reverse_proxy_server_group.

        Operation

        Yes

        Specify an operation type. Example: Reload configuration file.

        Nginx Installation Path

        Yes

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

        Modify configuration file before execution

        No

        Select this option for this example.

        Nginx Configuration File Path

        Yes

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

        Configuration File Backup Path

        No

        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

        Yes

        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 displayed dialog box, set the parameters as follows and click Confirm.
        Table 15 Parameter description

        Parameter

        Mandatory

        Description

        Stage Name

        Yes

        Example: Gray_release_of A-side_node.

        Always Run

        Yes

        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 displayed dialog box, set the parameters as follows and click OK.
        Table 16 Parameter description

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Gray_release_of A-side_node.

        Select Task

        Yes

        Select Gray_release_of A-side_node.

        Build Task

        No

        Leave it blank for this example.

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

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Bring_A-side_node_online.

        Always Run

        Yes

        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

        Mandatory

        Description

        Name

        Yes

        Example: Gray_release_of A-side_node.

        Reviewer

        Yes

        Select the service verification personnel.

        Review Mode

        Yes

        Select Review by all.

        Timeout Processing

        Yes

        Select Review failed and pipeline terminated.

        Review Duration

        Yes

        Example: 4 hours.

        Description

        No

        Enter the review description.

      • Click , click the Deploy tab, select Deploy, and click Add. In the displayed dialog box, set the parameters as follows and click OK.

        Table 19 Parameter description

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Bring_A-side_node_online.

        Select Task

        Yes

        Select Bring_A-side_node_online.

        Build Task

        No

        Leave it blank for this example.

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

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Gray_release_of_B-side_node.

        Always Run

        Yes

        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 displayed dialog box, set the parameters as follows and click OK.
        Table 21 Parameter description

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Gray_release_of_B-side_node.

        Select Task

        Yes

        Select Gray_release_of_B-side_node.

        Build Task

        No

        Leave it blank for this example.

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

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Bring_B-side_node_online.

        Always Run

        Yes

        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

        Mandatory

        Description

        Name

        Yes

        Example: Gray_verification_of_B-side_node.

        Reviewer

        Yes

        Select the service verification personnel.

        Review Mode

        Yes

        Select Review by all.

        Timeout Processing

        Yes

        Select Review failed and pipeline terminated.

        Review Duration

        Yes

        Example: 4 hours.

        Description

        No

        Enter the review description.

      • Click , click the Deploy tab, select Deploy, and click Add. In the displayed dialog box, set the parameters as follows and click OK.

        Table 24 Parameter description

        Parameter

        Mandatory

        Description

        Name

        Yes

        Example: Bring_B-side_node_online.

        Select Task

        Yes

        Select Bring_B-side_node_online.

        Build Task

        No

        Leave it blank for this example.

    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 check 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;
            }
       }
    }