Nginx Test

Try the below test to see how good you are working with nginx and looking things up when you need it.

Google is allowed

Test

You will be running a minimal config of nginx on your virtual server and implement features that have been listed below.

Go through all the steps and verify that whatever has been asked from you is working properly before proceeding.

Fork the repo in you indvidual users in gitlab. (This will be done by clicking the fork icon on this repo)

Clone the forked repo to your box

Make sure that there is no nginx process running:

sudo systemctl stop nginx

ps aux | grep nginx
# this hsould not return any nginx process

Once you are sure that nginx is not running:

cd nginxTest

sudo nginx -c ./nginx.conf -t
# That will test the minimal config provided

sudo nginx -c ./nginx.conf
# That will start the nginx server with the minimal config provided

sudo nginx -c ./nginx.conf -s reload
# That will reload nginx and any changes in nginx.conf will be reflected

#The above three commands will be used multiple times so it is advised to
#create aliases fof the same
Once nginx server is started, make sure that the nginx is doing what it was supposed to do:
$ curl http://127.0.0.1:8000
Hello, you are up and running
That confirms that your nginx setup is working as expected.

Now, we start the test:

Here are some instructions:

All changes need to be made to nginx.conf only.

You are supposed to get them using nginx alone.

You are free to surf through the nginx documentaion as well as the internet in general.

Whatever resources that were used need to be documented in the commit after you solve each test case.

(Failure to document would work against you)

After you have tested that your config works, you will commit it to your forked git repo with the following message syntax:

Stage <stage number> <your adusername>
Resources used:
* <link1>
* <link2>
...
* <linkN>

For eg.

Stage 2 sam.s
Resources used:
* http://nginx.org/en/docs/http/ngx_http_core_module.html

If you want to skip a stage, you still need to commit the changes that you made in the effort to get it to work.

Only related docs to be added to the commit message

Do not forget to check the config / reload nginx before testing changes

Stage 1

$ curl http://127.0.0.1:8000 -H "Host: abc.com"
You are looking at abc.com

$ curl http://127.0.0.1:8000 -H "Host: bleh.com"
You are looking at bleh.com

$ curl http://127.0.0.1:8000 -H "Host: wroom.com"
You are looking at wroom.com

$ curl http://127.0.0.1:8000 -H "Host: anything.com"
You are looking at anything.com

$ curl http://127.0.0.1:8000 -H "Host: wonderingIfIShouldStop.com"
You are looking at wonderingIfIShouldStop.com

$ curl http://127.0.0.1:8000 -H "Host: wellIWillStopNow.com"
You are looking at wellIWillStopNow.com

$ curl http://127.0.0.1:8000
You are looking at

#Hint: There are two ways to accomplish the above, and the simpler way does
#not use multiple server blocks

#Do not forget to commit the changes once we are done

Stage 2

$ curl http://localhost:8000/header -H "Hello: World"
Header Hello has value World

$ curl http://localhost:8000/header -H "Hello: Love"
Header Hello has value Love

#Hint: notice the Hello not changing

Stage 3

$ curl http://127.0.0.1:8000/hello?world=nice
You are looking at uri hello where world is nice

$ curl http://127.0.0.1:8000/hello?world=notnice
You are looking at uri hello where world is notnice

$ curl http://127.0.0.1:8000/something?world=nice
You are looking at uri something where world is nice

# The hint is in the response

Stage 4

#Ever searched for whats my IP on google to get your public IP?

#Implement something similar in nginx

#From box with ip W.X.Y.Z:
$ curl http://<ip of box where nginx is running>:8000/ip
W.X.Y.Z

#Hint: nginx must be storing the IP of the the requestors IP in some
#variable. It is some sort of *_addr.

Stage 5

$ curl http://localhost:8000/?access=0
You may not pass as you do not have access

$ curl http://localhost:8000/?access=1
Welcome, you are the chosen one

#Hint: simple way would be to use if, but map is more awesome