All Products
Search
Document Center

Object Storage Service:Create an NGINX application by using OSS and ROS

Last Updated:Mar 08, 2024

You can compile stack templates to describe cloud computing resources, such as Elastic Compute Service (ECS) and ApsaraDB RDS instances, and the dependencies between resources in the stack templates by using Resource Orchestration Service (ROS). The orchestration engine of ROS automatically creates and configures all resources based on templates to implement automated deployment and O&M. This topic describes how to create an NGINX application by using Object Storage Service (OSS) and ROS.

Prerequisites

Step 1: Upload the NGINX installation package to the bucket

  1. Log on to the OSS console.

  2. In the left-side navigation pane, click Buckets. On the Buckets page, find and click the desired bucket.

  3. In the left-side navigation tree, choose Object Management > Objects.

  4. Upload the downloaded NGINX installation package.

    Set the access control list (ACL) of the NGINX installation package to public-read and keep the default settings for other parameters. For more information about how to upload an object, see Upload objects.

  5. Obtain the object URL.

    Click View Details on the right side of the NGINX installation package, and then click Copy Object URL.image

Step 2: Create a stack by using ROS

  1. Select the template that you want to use to create a stack.

    1. Log on to the ROS console.

    2. In the left-side navigation pane, click Stacks.

    3. In the top navigation bar, select China (Hangzhou) from the region drop-down list.

    4. On the Stacks page, click Create Stack and select Use ROS from the drop-down list.

    5. In the Select Template step, set Specify Template to Select an Existing Template and Template Import Method to Enter Template Content. In the Template Content section, click ROS and JSON, enter the following template content in the code editor, and then click Next.

      {
        "ROSTemplateFormatVersion": "2015-09-01",
        "Description": "",
        "Parameters": {
          "NginxDownloadUrl": {
            "Type": "String",
            "Description": {
               
              "en": "The download path of nginx-*.rpm"
            },
            "Label": {
               
              "en": "Nginx Download Url"
            }
          },
          "ZoneId": {
            "AssociationProperty": "ALIYUN::ECS::Instance:ZoneId",
            "Type": "String",
            "Description": {
                
              "en": "Availability Zone ID.<br><b>note: <font color='blue'>before you make a selection, please confirm that the Availability Zone supports the specification of creating ECS resources, which is recommended to be different from other VSwitch Availability Zone</font></b>"
            },
            "Label": {
               
              "en": "VSwitch Availability Zone"
            }
          },
          "ImageId": {
            "Default": "centos_7",
            "Type": "String",
            "Description": {
                
              "en": "Image ID,Please use Centos7, see detail: <b><a href='https://www.alibabacloud.com/help/en/doc-detail/112977.html' target='_blank'><font color='blue'>Find the mirror</font></a></b>"
            },
            "Label": {
               
              "en": "Image"
            }
          },
          "InstanceType": {
            "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
            "AssociationPropertyMetadata": {
              "ZoneId": "ZoneId"
            },
            "Label": {
               
              "en": "Instance Type"
            },
            "Type": "String",
            "Description": {
               
              "en": "<font color='blue'><b>1.Before selecting the model please confirm that the current available zone under the model is in stock, some models need to be reported in advance</b></font><br><font color='blue'><b>2.List of optional models</font><br></b></font>[ecs.c5.large <font color='green'>2vCPU 4GiB Intranet bandwidth1Gbps In-grid sending and receiving packages30MillionPPS</font>]<br></b>[ecs.c5.xlarge <font color='green'>4vCPU 8GiB Intranet bandwidth1.5Gbps In-grid sending and receiving packages50MillionPPS</font>]<br></b>[ecs.c5.2xlarge <font color='green'>8vCPU 16GiB Intranet bandwidth2.5Gbps In-grid sending and receiving packages80MillionPPS</font>]"
            }
          },
          "SystemDiskCategory": {
            "Default": "cloud_efficiency",
            "Label": {
               
              "en": "System Disk Type"
            },
            "Type": "String",
            "Description": {
              "en": "<font color='blue'><b>Optional values:</b></font><br>[cloud_efficiency: <font color='green'>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font color='green'>SSD Cloud Disk</font>]<br>[cloud_essd: <font color='green'>ESSD Cloud Disk</font>]<br>[cloud: <font color='green'>Cloud Disk</font>]<br>[ephemeral_ssd: <font color='green'>Local SSD Cloud Disk</font>]",
               
            },
            "AllowedValues": [
              "cloud_efficiency",
              "cloud_ssd",
              "cloud",
              "cloud_essd",
              "ephemeral_ssd"
            ]
          },
          "InstancePassword": {
            "Type": "String",
            "Description": {
                
              "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)."
            },
            "MinLength": 8,
            "Label": {
               
              "en": "Instance Password"
            },
            "AllowedPattern": "[0-9A-Za-z\\_\\-\\&:;'<>,=%`~!@#\\(\\)\\$\\^\\*\\+\\|\\{\\}\\[\\]\\.\\?\\/]+$",
            "NoEcho": true,
            "MaxLength": 30,
            "ConstraintDescription": {
               
              "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)."
            }
          },
          "SecurityGroup": {
            "Type": "String",
            "AssociationProperty": "ALIYUN::ECS::SecurityGroup::SecurityGroupId",
            "Description": {
               
              "en": "Please search the business security group ID starting with(sg-xxx)from console-ECS-Network & Security"
            },
            "Label": {
               
              "en": "Security Group ID"
            }
          },
          "VPC": {
            "AssociationProperty": "ALIYUN::ECS::VPC::VPCId",
            "Type": "String",
            "Description": {
               
              "en": "Please search the ID starting with (vpc-xxx)from console-Virtual Private Cloud"
            },
            "Label": {
               
              "en": "Existing VPC Instance ID"
            }
          },
          "VSwitch": {
            "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId",
            "Type": "String",
            "Description": {
               
              "en": "Please search the business vswitch ID starting with(vsw-xxx)from console-Virtual Private Cloud-VSwitches"
            },
            "Label": {
               
              "en": "VSwitch ID"
            }
          }
        },
        "Metadata": {
          "ALIYUN::ROS::Interface": {
            "ParameterGroups": [
              {
                "Parameters": [
                  "VPC",
                  "VSwitch",
                  "SecurityGroup"
                ],
                "Label": {
                  "default": {
                     
                    "en": "Infrastructure Configuration"
                  }
                }
              },
              {
                "Parameters": [
                  "ZoneId",
                  "ImageId",
                  "InstanceType",
                  "SystemDiskCategory",
                  "InstancePassword",
                  "NginxDownloadUrl"
                ],
                "Label": {
                  "default": {
                     
                    "en": "ECS Configuration"
                  }
                }
              }
            ],
            "TemplateTags": [
              "acs:example:Linux application service: Create an NGINX application by using ROS_OOS"
            ]
          }
        },
        "Resources": {
          "WebServer": {
            "Type": "ALIYUN::ECS::Instance",
            "Properties": {
              "InternetMaxBandwidthOut": 80,
              "IoOptimized": "optimized",
              "VpcId": {
                "Ref": "VPC"
              },
              "UserData": {
                "Fn::Join": [
                  "",
                  [
                    "#!/bin/bash \n",
                    "NginxUrl=",
                    {
                      "Ref": "NginxDownloadUrl"
                    },
                    "\n",
                    "yum -y install aria2 \n",
                    "aria2c $NginxUrl \n",
                    "rpm -ivh nginx-*.rpm \n",
                    "yum -y install nginx \n",
                    "systemctl enable nginx.service \n",
                    "systemctl restart nginx.service \n"
                  ]
                ]
              },
              "SecurityGroupId": {
                "Ref": "SecurityGroup"
              },
              "VSwitchId": {
                "Ref": "VSwitch"
              },
              "ImageId": {
                "Ref": "ImageId"
              },
              "InstanceType": {
                "Ref": "InstanceType"
              },
              "SystemDiskCategory": {
                "Ref": "SystemDiskCategory"
              },
              "Password": {
                "Ref": "InstancePassword"
              }
            }
          }
        },
        "Outputs": {
          "NginxUrl": {
            "Value": {
              "Fn::Join": [
                "",
                [
                  "http://",
                  {
                    "Fn::GetAtt": [
                      "WebServer",
                      "PublicIp"
                    ]
                  },
                  ":80"
                ]
              ]
            }
          }
        }
      }
  2. Configure the parameters.

    1. In the Configure Parameters step, specify the Stack Name parameter.

    2. In the Configure Template Parameters section, configure the following parameters.

      Section

      Parameter

      Description

      Infrastructure Configuration

      Existing VPC Instance ID

      Select a virtual private cloud (VPC) from the drop-down list.

      VSwitch ID

      Select a vSwitch from the drop-down list.

      Security Group ID

      Select a security group from the drop-down list.

      ECS Configuration

      VSwitch Availability Zone

      Select a vSwitch zone based on your business requirements, such as Zone G.

      Image

      Enter centos_7.

      Instance Type

      Select an instance type based on your business requirements.

      System Disk Type

      Select cloud_ssd.

      Instance Password

      Enter the custom logon password of the ECS instance.

      Nginx Download Url

      Enter the object URL of the NGINX installation package that you obtained in Step 1.

    3. In the Configure Stack Settings section, retain the default settings.

    4. Click Create.

  3. Visit the homepage of NGINX in a browser.

    1. Click the stack that you created.

    2. Click Outputs and then click the URL of NGINX.

      nginx

      After you click the URL of NGINX, you are redirected to the homepage of NGINX.

      3

      If you cannot access the homepage of NGINX, add the default port HTTP(80) to the current security group. For more information, see Add a security group rule.