Accessing OBS Through an NGINX Reverse Proxy
Application Scenario
Generally, you can access OBS using a bucket's access domain name (for example, https://bucketname.obs.eu-west-101.myhuaweicloud.eu) 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 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.
Prerequisites
- You have known the region and access domain name of the bucket. For example, the access domain name of a bucket in the EU-Dublin region is nginx-obs.obs.eu-west-101.myhuaweicloud.eu. 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
- Install NGINX on an ECS.
In this example, CentOS 7.6 is used as an example.
- Log in to the ECS where you will set up the NGINX reverse proxy server.
- 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
- Run the following command to create the NGINX yum repository:
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
- Run the following command to install NGINX:
yum -y install nginx
- Run the following commands to start NGINX and configure NGINX to start upon system startup:
systemctl start nginx systemctl enable nginx
- 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
- Modify the NGINX configuration file to configure the reverse proxy for your OBS bucket.
- Run the following command to open the default.conf file:
vim /etc/nginx/conf.d/default.conf
- 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.eu-west-101.myhuaweicloud.eu; #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.eu-west-101.myhuaweicloud.eu
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.eu-west-101.myhuaweicloud.eu
- Press the Esc key and enter :wq to save the configuration and exit.
- Run the following command to check the status of the NGINX configuration file:
nginx -t
- Run the following command to restart the NGINX service for the configuration to take effect:
systemctl stop nginx systemctl start nginx
- Run the following command to open the default.conf file:
- (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.
- In the navigation pane of OBS Console, choose Object Storage.
- In the bucket list, click the bucket you want to go to the Objects page.
- In the navigation pane, choose Permissions > Bucket Policies.
- Click Create.
- In the first row of the bucket policy template, click Create Custom Policy.
- 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: Select Anonymous user.
- User Policy: Select Include specified users.
Resource
- Resource: Select both Current bucket and Objects in bucket.
- Resource Policy: Select Include specified resources.
Actions
- Select Get* and List*.
- Operation Strategy: Select Include selected.
Conditions
- Click Next in the lower right corner.
- Click Create.
- 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
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.