By Sagar Sharma
Hello all!
Q1. How to block access using the server IP and return error 444 on SSL? As you can see in my configuration it blocks at port 80.
Q2. I have redirected non-www to www, is that correct?
The configuration for my webserver is:
server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.(?!well-known) {
deny all;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # m$
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; #$
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://www.example.com;
} # managed by Certbot
if ($host = example.com) {
return 301 https://www.example.com;
} # managed by Certbot
listen 80;
server_name example.com www.example.com;
return 444; # managed by Certbot
}
Kindly help me resolve this.
Thanks in advance!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi @sagarsharmaweb,
You can add this server block to your configuration.
server {
listen 80 default_server;
server_name "";
return 444;
}
You need to specify “defaultserver” parameter so that all non available server requests goes to this server block which throws 444 error. The “defaultserver” parameter cannot be present in any other server block.
444 : CONNECTION CLOSED WITHOUT RESPONSE
After you make the changes, don’t forget to restart nginx
service nginx restart
Regards, KFSys
If you want to block the IP address that uses 443 port, just add listen to 443 and change the server_name with your IP address, so it looks like this:
server {
listen 443;
server_name your_ip_address;
return 403;
}
Don’t forget to check the syntax if it is successful or not: sudo nginx -t
And reload your Nginx server: sudo systemctl reload nginx
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
