Blocking IP Address: 8080 in Nginx - Tech Support
In this article, we will discuss how to block an IP address from accessing port 8080 on an Nginx server. This is useful when you want to prevent unauthorized access to your server or a specific application running on it.
Prerequisites
Before we begin, ensure that you have the following:
- Access to the Nginx server with administrative privileges
- Basic understanding of Nginx configuration files
Blocking IP Addresses in Nginx
To block an IP address in Nginx, you need to modify the configuration file. The default configuration file is located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf depending on your system.
Open the configuration file using your favorite text editor with administrative privileges:
sudo nano /etc/nginx/nginx.conf
Add the following lines inside the http block to block a specific IP address:
http {
...
server {
...
listen 8080;
server_name your_domain_or_IP;
# Block a specific IP address
deny 192.168.1.1;
# Allow all other IP addresses
allow all;
...
}
}
Replace 192.168.1.1 with the IP address you want to block. Save and close the file.
To apply the changes, test the configuration file and restart Nginx:
sudo nginx -t
sudo systemctl restart nginx
Testing the Configuration
To test if the IP address is blocked, use the curl command from a different terminal:
curl -I http://your_domain_or_IP:8080
Replace your_domain_or_IP with your server's domain name or IP address. If the IP address is blocked, you should see a "403 Forbidden" response.
References
This article is for informational purposes only. The Cloud Helper team is not responsible for any damages or losses resulting from the use or misuse of the information provided.
-- Generated by Cloud Helper Tech Support