IP canonicalization in Nginx

Posted July 21, 2014 6k views

How to solve IP canonicalization in Nginx?

ls /etc/nginx/sites-enabled


cat /etc/nginx/sites-enabled/wordpress


1 comment

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.

Submit an Answer
2 answers

Make sure server_name is set to and that the listen line doesn’t contain default_server in /etc/nginx/sites-enabled/wordpress.

Then, add a new virtualhost called default with the following config:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    return 403;

Finally, restart nginx:

sudo service nginx restart

This should make sure your site is served only when you’re accessing it using the domain name. The IP address will just return a 403 Forbidden error.

I have this question too, but I already run more than one site. I do have a file in sites available title digitalocean and this is the key part I tried to make it like your example above.“`server {
listen 80 defaultserver;
listen [::]:80 default

    root /usr/share/nginx/html/index.html;

    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name _ localhost;

    return 403;
the ip address doesnt serve anything which I dont think is good.