Current Location: Home> Latest Articles> How to Secure Web Service Access with Docker Containers and Nginx Proxy Server

How to Secure Web Service Access with Docker Containers and Nginx Proxy Server

M66 2025-07-13

How to Secure Web Service Access with Docker Containers and Nginx Proxy Server

With the rapid development of the internet, web service security has become increasingly important. To protect the access control of web services, using Docker containers combined with Nginx proxy servers is an effective solution. This article will guide you through the steps of configuring Docker containers and Nginx proxy servers to secure web services, along with complete code examples.

What is a Docker Container?

Docker is an open-source containerization platform that packages applications and their dependencies into independent containers. This helps ensure portability and consistency across environments. Docker enables more efficient application deployment, better resource utilization, and improved system reliability.

What is an Nginx Proxy Server?

Nginx is a high-performance web server and reverse proxy server, widely used for load balancing, SSL termination, and security control. By configuring an Nginx proxy server, we can effectively control web service access, enhancing the security of the system.

Steps to Configure Nginx Proxy Server with Docker Containers

Install Docker

First, you need to install Docker on your system. You can refer to the official Docker installation documentation for the process. After installation, use the following command to verify if Docker is installed successfully:

<span class="fun">docker --version</span>

Create Docker Container

Next, you will need to create a Docker container to run the Nginx proxy server. Use the following command to create a container named “nginx-proxy” and map the container's port 80 to the host's port 80:

<span class="fun">docker run --name nginx-proxy -p 80:80 -d nginx</span>

This command will start an Nginx container named “nginx-proxy” and run it in the background.

Configure Nginx Proxy Server

Next, you need to configure Nginx to forward web requests to the appropriate backend service. Here is an example Nginx configuration:

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://web-service;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

upstream web-service {
    server web-service-container:8080;
}

This configuration specifies that Nginx will listen on port 80 and forward all requests to a backend server named “web-service.” It also configures HTTP headers to ensure that client information is correctly passed to the upstream server.

Start Web Service Container

Now, you need to start a web service container named “web-service-container” and map its port 8080 to the host's port 8080. You can do this with the following command:

<span class="fun">docker run --name web-service-container -p 8080:8080 -d web-service</span>

This command will start a web service container and link it with the Nginx proxy server.

Conclusion

By combining Docker containers with Nginx proxy servers, we can effectively protect web service access control and enhance the security of the system. This article provided detailed steps for installing Docker, configuring the Nginx proxy server, and starting the web service container. We hope this guide helps you build a secure web service architecture.