All Products
Search
Document Center

Object Storage Service:Use an ECS instance that runs Windows to configure a reverse proxy for access to OSS

Last Updated:Sep 28, 2023

The IP address used to access an Object Storage Service (OSS) bucket dynamically changes. You can configure a reverse proxy on an Elastic Compute Service (ECS) instance to access the OSS bucket by using a static IP address.

Background information

OSS uses RESTful APIs to provide services. You can access an OSS bucket by using the default domain name of the bucket or a custom domain name that is mapped to the bucket. However, you may need to use a static IP address to access OSS in specific scenarios.

  • For security reasons, some enterprises need to configure outbound rules to specify that internal employees and business systems can access only the specified public IP addresses. However, the IP addresses used to access a bucket in OSS dynamically change. In this case, enterprises need to frequently modify firewall rules to meet their requirements.

  • The network architecture of Alibaba Finance Cloud allows only requests from Alibaba Finance Cloud to access internal network-specific buckets in Alibaba Finance Cloud. Access requests from the Internet are denied.

To resolve these issues, you can use an ECS instance to configure a reverse proxy for access to OSS.

Procedure

  1. Create an ECS instance.

    In this example, an ECS instance of Windows Server 2019 Datacenter 64-bit is used. Make sure that the instance and the bucket that you want to access are located in the same region.

    For more information about how to create an ECS instance, see Create and manage an ECS instance by using the ECS console (express version).

  2. Connect to an ECS instance.

    For information about how to connect to an ECS instance, see Create and manage an ECS instance by using the ECS console (express version).

  3. Download NGINX and decompress the package.

    In this example, Nginx 1.19.2 is used.

  4. Modify the nginx.conf file.

    Important
    • In this topic, a demo environment is used as an example. To ensure data security, we recommend that you configure the HTTPS module based on your actual scenario. For more information, see Install SSL certificates on NGINX or Tengine servers.

    • You can configure a reverse proxy for only one bucket if you use this configuration method.

    1. Go to the conf directory and open the nginx.conf file by using a notepad.

    2. Modify the content of the nginx.conf file.

      worker_processes  1;
      events {
          worker_connections  1024;
      }
      
      http {
          include       mime.types;
          default_type  application/octet-stream;
      
          keepalive_timeout  65;
          server {
              listen       80;
              server_name  47.**.**.43;
      
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
              }
      
             location / {
                  proxy_pass  http://bucketname.oss-cn-hangzhou-internal.aliyuncs.com;
                  #proxy_set_header Host $host;
              }
         }
      }

      Parameter

      Description

      server_name

      The IP address used to provide the reverse proxy service. Set this parameter to the public IP address of the ECS instance.

      proxy_pass

      The domain name for redirection.

      • If the ECS instance and the bucket that you want to access are located in the same region, specify the internal domain name of the bucket. For more information, see the "Access OSS over the internal network" section of the OSS domain names topic.

      • If the ECS instance and the bucket that you want to access are located in different regions, specify the public domain name of the bucket. For more information, see the "Access OSS over the public network" of the OSS domain names topic.

      • If you want to preview an image object or web page object in a bucket by using a browser, take note of the following items: To ensure security, when you access an image object or web page object in a bucket by using the default domain name of the bucket in a browser, the object is downloaded. To preview an image object or web page object by using a browser, map a custom domain name to the bucket in which the object is stored and add the custom domain name to the value of the proxy_pass parameter. For more information, see Map custom domain names.

      proxy_set_header Host

      If you add this parameter, the $host value is replaced with the IP address of the ECS instance when NGINX sends a request to OSS.

      You must add this parameter in the following scenarios:

      • Signature errors occur.

      • The custom domain name that is mapped to the bucket is resolved to the public IP address of the ECS instance, and you need to preview image objects or web page objects in the bucket by using a browser. You can map the custom domain name to the bucket for which a reverse proxy is configured without adding a CNAME record for the custom domain name. In this case, you can set the proxy_pass parameter to the internal or public domain name of the bucket. For more information, see Map custom domain names.

      Note

      This parameter applies to scenarios in which a custom domain name is used to request access to a proxy server. If you use an IP address to directly request access to the proxy server, you must add the proxy_set_header Host $host parameter to the nginx.conf file.

  5. Go to the directory in which the NGINX executable file is located. Double-click nginx.exe to start NGINX.

  6. Enable TCP port 80 of the ECS instance.

    By default, NGINX uses TCP port 80. Therefore, you must enable TCP port 80 when you configure a security group for the ECS instance.

    For more information, see Add a security group rule.

  7. Add the object path to the public IP address of the ECS instance to access OSS resources.

    In this example, the default domain name is used. When you use a local browser to access OSS resources, OSS resources are downloaded by default. If you want to preview the OSS resources that you access, you must use a custom domain name when you configure the proxy_pass parameter.

    Note

    If the object access control list (ACL) is private, you must sign the object URL. For more information, see Add signatures to URLs.

References