Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Object Storage Service/ Best Practices/ Accessing Data Stored in OBS/ Accessing OBS Through an NGINX Reverse Proxy

Accessing OBS Through an NGINX Reverse Proxy

Updated on 2024-10-17 GMT+08:00

Application Scenario

Generally, you can access OBS using a bucket's access domain name (for example, https://bucketname.obs.ap-southeast-1.myhuaweicloud.com) provided by OBS or using 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 OBS 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.

Solution Architecture

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 and access domain name of the bucket. For example, the access domain name of a bucket in the CN-Hong Kong region is nginx-obs.obs.ap-southeast-1.myhuaweicloud.com. To obtain the information, see Querying Basic Information of a Bucket.
  • You have a Linux ECS in the same region. CentOS is used here as an example. For details, see Purchasing an ECS.
  • 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.

    In this example, CentOS 7.6 is used as an example.
    1. Log in to the ECS where 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.
      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 the NGINX yum repository:
      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.
            proxy_buffering off;  # Disable the proxy buffer (memory).
      
            location / {
                 proxy_pass  https://nginx-obs.obs.ap-southeast-1.myhuaweicloud.com;  #Enter the OBS bucket domain name that starts with http:// or https://.
                 index  index.html index.htm ;  #Specify the homepage of the website. If there are multiple files, NGINX checks the files based on their enumeration sequence.
              }
      }
      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.ap-southeast-1.myhuaweicloud.com

      Note:

      When you use an API, SDK, or obsutil for calling, set this parameter to the region domain name. The following is an example:

      obs.ap-southeast-1.myhuaweicloud.com

      proxy_buffering

      Whether to enable the proxy buffer. The value can be on or off.

      If this parameter is set to on, NGINX stores the response returned by the backend in a buffer and then sends the data to the client.

      If this parameter is set to off, NGINX sends the response to the client as soon as it receives the data from the backend.

      Default value: on

      Example: proxy_buffering off

    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. (Optional) Configure an OBS bucket policy to allow the IP address of the NGINX proxy server to access OBS.

    If your bucket is publicly read or the URL needs to have a signature contained when accessing objects in a private bucket, skip this step. For details, see Authentication of Signature in a URL.

    If you do not want URLs containing a signature to access resources in your private bucket, configure the following bucket policy that allows only the IP address of the NGINX proxy server to access your bucket.

    1. In the navigation pane of OBS Console, choose Object Storage.
    2. In the bucket list, click the bucket you want to go to the Objects page.
    3. In the navigation pane, choose Permissions > Bucket Policies.
    4. Click Create.
    5. Choose a policy configuration method you like. Visual Editor is used here.
    6. Configure the following parameters.
      Table 2 Bucket policy parameters

      Parameter

      Description

      Policy Name

      Enter a policy name.

      Policy Content

      Effect

      Select Allow.

      Principal

      • Select All accounts.

      Resources

      • Method 1:
        • Select Entire bucket (including the objects in it).
      • Method 2:
        • Select Current bucket and Specified objects.
        • Set the resource path to * to indicate all objects in the bucket.

      Actions

      • Choose Customize.
      • Select Get* and List*.

      Conditions (Optional)

      • Key: Select SourceIp.
      • Condition Operator: Select IpAddress
      • Value:
        • If the ECS uses a public DNS, the value is as follows:

          Elastic IP address of the ECS

        • If the ECS uses a Huawei Cloud private DNS, the value is as follows:
          100.64.0.0/10,214.0.0.0/7,Private IP address of the ECS
          NOTE:

          You can click Add to configure three IP addresses (CIDR blocks).

          IP addresses in the range starting with 100 or 214 are for ECSs to access OBS through an internal network.

    7. 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

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback