Nginx 101 — Part 2

Sachith Muhandiram
1 min readJul 7, 2020

--

https://logos-download.com/wp-content/uploads/2016/09/Nginx_logo.png

I hope you have basic understanding about Nginx. What it is and how we can use it as a proxy. I have explained them in my previous port. Today lets talk about some other benefits we can get from Nginx (before going to LoadBalancing). This will be a shorter description.

Regular Expressions

We can use regular expressions in our nginx configuration to do simple routing. ~ is used to indicate we are going to use regex in our nginx config. Following config can be used to block serving .jpg images to users.

location /images {
root /home/project/images/;
}
# check whether it tries to serve .jpg files.location ~.jpg {
return 403;
}

This configuration will block any request coming to /images/[a-z0-9].jpg

Content blocking

If we want to block users accessing some specific routes over the internet, we can use nginx config.

server {    listen 80;    location /admin {        return 403;
}
}

Above configuration will simply block users accessing our_domain/admin route over the internet (as port 80 is used). But still this will allow users to access same route using a port (if its running there). Such as our_domain:7800/admin

--

--

Sachith Muhandiram
Sachith Muhandiram

Written by Sachith Muhandiram

DevOps who is willing to learn and try new things.

No responses yet