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!
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.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.