Code Monkey home page Code Monkey logo

nginx-simple-proxy-test's Introduction

nginx simple proxy test

Based on nginx documentation Beginner's Guide.

Prerequisites

  • Docker (or equivalent, need commands for 'docker' and 'docker-compose')
  • a terminal application and basic cli knowledge
  • curl
  • grep

Outcomes

Observe how nginx can proxy http from another server.

Instructions

  1. Download this git archive and cd into it
  2. Use the below command to set up the networked containers
docker-compose up -d
# Expect output similar to:
# ✔ Network nginx_my-network  Created                                                                                                                                                     0.0s 
# ✔ Container nginx-webapp-1  Started                                                                                                                                                     0.0s 
# ✔ Container nginx-proxy-1   Started                                                                                                                                                     0.0s 
  1. Confirm the container names:
docker container ps
# Expect output similar to
# CONTAINER ID   IMAGE          COMMAND                  CREATED         STATUS         PORTS                  NAMES
# xxxxxxxxxxxx   nginx:1.27.0   "/docker-entrypoint.…"   3 seconds ago   Up 3 seconds   0.0.0.0:8070->80/tcp   nginx-proxy-1
# xxxxxxxxxxxx   nginx:1.27.0   "/docker-entrypoint.…"   3 seconds ago   Up 3 seconds   0.0.0.0:8090->80/tcp   nginx-webapp-1
  1. Confirm the containers have the correct local directores mounted:
curl -s localhost:8070 | grep title
# Expect: 
#<title>Welcome to proxy host!</title>
curl -s localhost:8090 | grep title
# Expect: 
#<title>Welcome to webapp host!</title>
  1. Get the web application's IP Address using the name from above (in this case "nginx-webapp-1"):
docker container inspect nginx-webapp-1 | grep IPAddress
# Expect:
#  "SecondaryIPAddresses": null,
#  "IPAddress": "",
#    "IPAddress": "172.21.0.2",
  1. Confirm the proxy container can see the web app container (in this case the IP address is 172.21.0.2, the address will be different on your system)
docker exec nginx-proxy-1 sh -c 'curl -s 172.21.0.2:80 | grep title'
# Expect:
# <title>Welcome to webapp host!</title>
  1. Edit the proxy container nginx config to perform proxying of the webapp container a. Add the "#" character to the beginning of lines 15 to 18 b. Remove the leading "#" character from the beginning of lines 24 to 26 c. Reload the configuration in the proxy container and test it
docker exec nginx-proxy-1 sh -c 'nginx -s reload'                   
# Expect: 
#2024/06/01 12:00:00 [notice] 50#50: signal process started
nginx % curl -s localhost:8090 | grep title                                 
# Expect:
#<title>Welcome to webapp host!</title>

If the result of the last command says "proxy" instead of "webapp" then recheck the above steps.

  1. Clean up
docker-compose down 
# Expect:
#✔ Container nginx-webapp-1  Removed                                                                                                                                                     0.1s 
#✔ Container nginx-proxy-1   Removed                                                                                                                                                     0.2s 
#✔ Network nginx_my-network  Removed    

nginx-simple-proxy-test's People

Contributors

adolph-trudeau-mdanderson avatar adolph avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.