Help Center > > Best Practices> Accessing OBS Through an NGINX Reverse Proxy

Accessing OBS Through an NGINX Reverse Proxy

Updated at: Jul 08, 2021 GMT+08:00

Background

Generally, you can access OBS through a bucket access domain name (for example, https://bucketname.obs.cn-north-4.myhuaweicloud.com) provided by OBS or through a user-defined domain name bound to an OBS bucket.

In some cases, you may need to use a fixed IP address to access OBS. For security purposes, some enterprises need to set a blacklist and a whitelist of external IP addresses. In this case, a fixed IP address is required. Also for security purposes, an OBS bucket does not have a fixed IP address, because the DNS service of HUAWEI CLOUD resolves the bucket access domain name to different IP addresses.

In this case, you can set up an NGINX reverse proxy server on an ECS so that you can access OBS through a fixed IP address.

Principles

This part explains how to deploy NGINX on an ECS and set up an NGINX reverse proxy server. The proxy is imperceptible. Requests are sent to the reverse proxy server, which then obtains the required data from OBS and returns the data to users. The reverse proxy server and OBS work as a whole. Only the IP address of the proxy server is exposed, while the actual domain name or IP address of OBS is hidden.

Figure 1 Principles of accessing OBS through an NGINX reverse proxy

Prerequisites

  • You have known the region where the bucket resides and bucket access domain name of the bucket. For example, the access domain name of the bucket in the CN North-Beijing4 region is nginx-obs.obs.cn-north-4.myhuaweicloud.com. Viewing Basic Information of a Bucket
  • You have a Linux ECS in the same region. CentOS is used here as an example. Purchasing an ECS with Customized Configurations
  • The ECS is bound with an EIP, so that you can download the NGINX installation package over the public network.

Procedure

  1. Install NGINX on an ECS.

    1. Log in to the ECS on which you will set up the NGINX reverse proxy server.
    2. Run the wget command to download the NGINX installation package for your operating system in use. We use CentOS 7.6 as an example.
      wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    3. Run the following command to create a YUM repository for NGINX. Also we use CentOS 7.6 as an example.
      rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
    4. Run the following command to install NGINX:
      yum -y install nginx
    5. Run the following commands to start NGINX and configure NGINX to start upon system startup:
      systemctl start nginx
      systemctl enable nginx
    6. Use a browser on any device to access http://ECS EIP. If the following information is displayed, NGINX is successfully installed.
      Figure 2 NGINX installed successfully

  2. Modify the NGINX configuration file to configure the reverse proxy for your OBS bucket.

    1. Run the following command to open the default.conf file:
      vim /etc/nginx/conf.d/default.conf
    2. Press the i key to go to the edit mode and modify the default.conf file.
      server {
            listen       80;
            server_name  **.**.**.**;  # Enter the EIP of the ECS.
            location / {
                 proxy_pass  https://nginx-obs.obs.cn-north-4.myhuaweicloud.com;  # Enter the bucket access domain name, starting with http:// or https://.
                 index  index.html index.htm ;
              }
      }
      Table 1 Parameters in the configuration file

      Parameter

      Description

      server_name

      IP address that provides the reverse proxy service. It is the fixed IP address that is exposed to end users for access.

      Enter the EIP of the ECS where the NGINX reverse proxy service is deployed.

      proxy_pass

      IP address of the proxied server.

      Enter the OBS bucket access domain name required in Prerequisites. The domain name must start with http:// or https://. Example:

      https://nginx-obs.obs.cn-north-4.myhuaweicloud.com

    3. Press the Esc key and enter :wq to save the configuration and exit.
    4. Run the following command to check the status of the NGINX configuration file:
      nginx -t
    5. Run the following command to restart the NGINX service for the configuration to take effect:
      systemctl stop nginx
      systemctl start nginx

  3. Configure an OBS bucket policy to allow the IP address of the NGINX proxy server to access OBS.

    To ensure data security in the bucket, configure the following two bucket policies based on a private bucket (without any bucket policies) to allow only the IP address of the Nginx proxy server to access the OBS bucket.

    1. On OBS Console, in the navigation pane on the left, choose Object Storage.
    2. In the bucket list, click a bucket name, and then the Overview page of the bucket is displayed.
    3. In the navigation pane on the left, choose Permissions > Bucket Policy.
    4. Click Create Bucket Policy.
    5. In the first row of the bucket policy template, click Create Custom Policy.
    6. Configure the following parameters.
      Table 2 Bucket policy parameters

      Parameter

      Description

      Policy View

      Select Visual editor.

      Policy Name

      Custom

      Policy Content

      Effect

      Select Allow.

      Principal

      • Principal: Anonymous user
      • User Policy: Include specified users.

      Resources

      • Resource: Select Current bucket and Object in bucket.
      • Resource Policy: Include specified resources.

      Actions

      • Select Get* and List*.
      • Operation Strategy: Include selected actions.

      Conditions

      • Conditional Operator: IpAddress
      • Key: SourceIp
      • Value:
        • If the ECS uses the private DNS of HUAWEI CLOUD, the value is 100.64.0.0/10.
        • If the ECS uses a public DNS, the value is the EIP of the ECS.
    7. Click Next in the lower right corner.
    8. Click Create.

  4. Verify the reverse proxy configuration.

    On any device, use the ECS EIP and object name to access specified OBS resources. If the resources are properly accessed, the configuration is successful.

    For example, visit http://ECS EIP/ocean.jpg.

    Figure 3 Using a fixed IP address to access OBS resources

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel