NGINX is a high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. It is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
NGINX is often used as a load balancer and HTTP cache in combination with other web servers. It excels in serving static content quickly and is designed to pass dynamic requests off to other software that is better suited for those purposes.
NGINX can be used to serve static files such as HTML, CSS, and JavaScript, proxy HTTP requests to other servers, handle SSL/TLS encryption, and much more. It’s configured by editing its text-based configuration files, where you can set up virtual hosts, manage access control, rewrite URLs, and set up redirects among other things.
Here’s a simple step-by-step guide to setting up NGINX using Docker.
Refer to Dockerfile Tutorial and Docker-Compose Tutorialfor more information on Dockerfile syntax.
To get started, pull the latest NGINX image from the Docker Hub:
docker pull nginx
You can run NGINX within a Docker container and expose it on port 8080:
docker run --name some-nginx -p 8080:80 -d nginx
This command will start an NGINX container named some-nginx
and bind port 8080 on your host to port 80 on the container.
Once the container is running, open your web browser and navigate to:
http://localhost:8080
You should see the default NGINX welcome page.
To customize the NGINX configuration, you can mount a custom configuration file into the container:
Create an nginx.conf
file on your host machine.
Mount it into your container:
docker run --name some-custom-nginx -v /path/to/your/nginx.conf:/etc/nginx/nginx.conf:ro -p 8080:80 -d nginx
Make sure to replace /path/to/your/nginx.conf
with the actual path to your custom configuration file.
To serve your own content instead of the default NGINX page, you can mount a directory:
docker run --name some-nginx -v /path/to/your/content:/usr/share/nginx/html:ro -p 8080:80 -d nginx
Replace /path/to/your/content
with the path to the directory that contains your HTML files.
NGINX is a versatile web server that can be easily set up in a Docker environment. Its lightweight nature and ability to handle a large number of connections make it an ideal choice for modern web applications.