Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Last active April 26, 2023 04:20
Show Gist options
  • Save j-thepac/b5f663612566614b9abc75b6abb607bb to your computer and use it in GitHub Desktop.
Save j-thepac/b5f663612566614b9abc75b6abb607bb to your computer and use it in GitHub Desktop.

NGINX with DOCKER

Summary

  • Serving Static Content (HTML, CSS, JavaScript)
  • Reverse Proxy (load balancing ): forward requests from clients to backend servers which handle the requests.
  • API Gateway(distributing traffic): Acts as a single entry point for all API requests and distributing traffic
  • SSL/TLS Termination: it decrypts incoming traffic, inspects it, and then re-encrypts it before sending it to the backend servers.
  • Caching: NGINX can also be used as an HTTP cache, which can improve website performance by caching frequently requested content and serving it directly from memory
  • load balancing All the above can be set in Config: etc/nginx/nginx.conf

Pre-Req:

  • Docker is already installed in the system.
  • Note:By default nginx runs on port 80

Example 1

	-------------------------- nginx.sh ----------------------------
	cd ~/Desktop
	mkdir nginx
	cd nginx
	echo '\<html\>\<body\> hi\</body\>\</html\>' >> test2.html 
	--------------------------------------------------------
	docker run -it --rm -d -p 8080:80 --name web -v $PWD:/usr/share/nginx/html nginx

open browser http://localhost:8080/test2.html docker stop container_id

Example 2

docker run -p 8000:80 --name nginx_test nginx:latest
  • open browser
  • open link localhost:8000 (You should be able to see the html page)
  • ctrl+c (to quit)
  • docker rm nginx_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment