Task:
Block specific web calls (e.g. /webservice?token=test123) and allow other calls using nginx.
Solution:
1. make changes in below nginx configuration file.
nano /etc/nginx/conf/80.conf
upstream backend { ip_hash; server 172.31.25.94; } server { listen 80; listen [::]:80; ## Block test123 call location /webservice { if ($arg_token = "test123") { return 403; } proxy_pass http://backend; } ## Block test123 call location / { proxy_pass http://backend; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-By $server_addr:$server_port; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; } }
Same thing need to do this in ssl.conf file as well.
2. verify nginx configuration.
nginx -t
3. reload nginx service.
systemctl reload nginx