NGINX S3 Gateway

Learn how to configure the NGINX S3 Gateway for use with Filebase.

What is NGINX?

NGINX is open-source web server software that can be used for HTTP caching, load balancing, reverse proxying, and media streaming. NGINX can be used to act as a caching gateway for content stored in a private bucket. By using NGINX, your content isn’t susceptible to public discovery on the Internet, and caching helps you save on your bandwidth charges. Additional benefits include security control, compression and content optimization, and access to internal applications.

To do this, the NGINX S3 Gateway can be used. This S3 gateway implementation includes the following features:

  • Support for a single S3 bucket.

  • Caches content for 1 hour.

  • Supports NGINX open source and NGINX plus.

  • Uses GET and HEAD requests only.

  • Is not configured with SSL/TLS.

Read below to learn how to configure the NGINX S3 Gateway for use with Filebase.

Prerequisites:

1. To use the NGINX S3 Gateway, a Docker container can be used. Start by cloning the following GitHub repository:

git clone https://github.com/nginxinc/nginx-s3-gateway.git

2. Next, navigate inside the newly created directory:

cd nginx-s3-gateway

3. Copy your certificate and key pair.

This key pair can be found in the F5 Customer Portal if you are a NGINX Plus user, or this key pair can be copied from a certificate generator. This certificate and key pair will need to be named nginx-repo.crt and nginx-repo.key respectively.

4. Store these two files in the ./plus/etc/ssl/nginx subdirectory.

5. Next, build the Docker container image.

Using Docker BuildKit is recommended since it supports passing a NGINX Plus license file into the container build. Use the following BuildKit command:

DOCKER_BUILDKIT=1 docker build -f Dockerfile.buildkit.plus -t nginx-plus-s3-gateway --secret id=nginx-crt,src=plus/etc/ssl/nginx/nginx-repo.crt --secret id=nginx-key,src=plus/etc/ssl/nginx/nginx-repo.key --squash .

Alternatively, the container can be built without BuildKit using the following command:

docker build -f Dockerfile.plus -t nginx-plus-s3-gateway .

6. Create a new file called s3-settings.env.

Enter the following text into this file:

S3_BUCKET_NAME=filebase-bucket-name
S3_ACCESS_KEY_ID=filebase-access-key
S3_SECRET_KEY=filebase-secret-ke
S3_SERVER=s3.filebase.com
S3_SERVER_PORT=443
S3_SERVER_PROTO=https
S3_REGION=us-east-1
AWS_SIGS_VERSION=4
ALLOW_DIRECTORY_LIST=true

Replace the following values:

  • S3_BUCKET_NAME: Your Filebase bucket name.

  • S3_ACCESS_KEY_ID: Your Filebase access key.

  • S3_SECRET_KEY: Your Filebase secret key.

7. Then, start the S3 Gateway Docker container using the following command:

If using NGINX Open Source, use the command:

docker run -it --env-file ./s3-settings.env -p8080:80 nginxinc/nginx-s3-gateway

If using NGINX Plus, use the command:

docker run -it --env-file ./s3-settings.env -p8080:80 nginx-plus-s3-gateway

8. Once running, the gateway can be accessed at http://localhost:8080.

9. To add additional configurations, you can:

  • Create configuration files such as gzip_compression.conf and store them in the ./etc/nginx/conf.d directory.

  • Then, add the following lines into your Dockerfile, which will automatically add any files with the .conf extension from the local directory:

FROM nginxinc/nginx-s3-gateway
COPY etc/nginx/conf.d /etc/nginx/conf.d

Last updated