Updated on 2024-05-25 GMT+08:00

Procedure

Restrictions

The official Nginx image is executed by the Nginx user. You need to set the file mask (umask) of the mounted file to 0022 to ensure that the Nginx user has the permission to read the mounted file. For details, see Configuring a Cloud Storage Mount Path.

Creating and Deploying a Nginx Component

  1. Log in to CAE.
  2. Choose Components.
  3. Select the created application and environment from the drop-down lists in the upper part of the page, and click Create Component.
  4. Configure the component by referring to Table 1.

    Table 1 Basic component information

    Parameter

    Description

    Component

    Enter a component name. In this practice, enter nginx.

    Version

    Enter a component version.

    In this practice, enter 1.0.0.

    Specifications

    Select instance specifications, for example, 0.5 Core and 1 GiB.

    Instances

    Set it to 1.

    Code Source

    Choose Images > Open Source Images > nginx. In this practice, select Nginx alpine-perl.

    Figure 1 Creating a component

  5. Click Configure Component.
  6. On the Component Configurations page, click Edit in the Access Mode module to configure the Nginx component.
  7. On the Load Balancing tab, click Add Load Balancer and set parameters.

    • Load Balancer: Select Built-in load balancer.
    • Health Check: Use the default value Start.
    • Access Control: Select Allow all IP addresses.
    • Protocol: Select TCP.
    • Listening Port: Enter 80.
    • Access Port: Enter an access port. In this practice, enter 14632.
    Figure 2 Adding external network access for load balancing

  8. Click OK.
  9. On the Component Configurations page, click Set and Deploy Component for the Nginx component access mode to take effect.
  10. After deployment, choose Components.

    Click the IP address in the Access Address column of the component to view the Nginx static web page.
    Figure 3 Accessing a static page

Cloud Storage Authorizations

  1. Choose System Settings > Cloud Storage Authorizations and click Edit. The Authorized Cloud Storage dialog box is displayed.
  2. Click Authorize Parallel File System.

    Figure 4 Authorize Parallel File System

  3. Click Create Parallel File System and enter a name, for example, test-nginx.
  4. Click OK.
  5. Select the created parallel file system. You can also enter a keyword in the search box above the list to filter data.
  6. Click Authorize. The parallel file system is authorized.

    You can view the authorized parallel file systems on the Authorized Cloud Storage page.

    Figure 5 Authorized parallel file system

Uploading a File

  1. Log in to OBS.
  2. Choose Parallel File Systems and click file system test-nginx to go to the parallel system page.

    Figure 6 Parallel file systems

  3. Choose Files and click Upload File.
  4. Drag the obtained static files index.html and test.html to the file upload area. You can also click add files to upload the files. The default storage class is Standard.

    Figure 7 Uploading a file

  5. Click Upload.

Configuring a Cloud Storage Mount Path

  1. Return to CAE and choose Component Configurations.
  2. Select the Nginx component from the drop-down list in the upper part of the page.
  3. Click Edit in the Cloud Storage module.

    Figure 8 Configuring cloud storage

  4. Click Set Parallel File System, enter the mount path, and set permissions.

    • Parallel File System: Select test-nginx authorized in Cloud Storage Authorizations.
    • File Mask (umask): Enter 0022.
    • Mount Path: path to which the data store is mounted. In this practice, use the default path /usr/share/nginx/html of nginx.
    • Required Permissions: permissions on the mount path and files in the mount path. The value can be Read/Write or Read only. In this example, select Read/Write.
    Figure 9 Configuring a cloud storage mount path
    • Do not mount a static file path to a directory that contains system files, such as / and /var/run. Otherwise, the components may be abnormal.
    • The Read/Write permission indicates that the component has the read and write permissions on the mount path and all files in the path. The Read only permission indicates that the component has only the read permission.

  5. Click OK. On the Cloud Storage page, click OK again.
  6. On the Component Configurations page, click Activate Settings.

    Figure 10 Activate Settings

Viewing an Updated Page

  1. Choose Components.
  2. Click the IP address in the Access Address column of the Nginx component to access the Nginx again. The page can be updated in real time (Press F5).

    The new index.html file can be customized and uploaded as required.

    Figure 11 Updated static page

    You can also access the new static page file using /test.html.

    Figure 12 Accessing the test page