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.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.
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
- 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. 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
- 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.
- Choose a policy configuration method you like. Visual Editor is used here.
- 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)
- 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.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot