Unable to access server by IP, but can access by domain name.

I am on Ubuntu with Nginx.

When I try to access the server by IP, I get a 404 error.

My server configuration looks like this:

server {
        listen 443 ssl;

        root /var/www/wordpress;


        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php$is_args$args;

        location = /favicon.ico { log_not_found off; access_log off; }
        location = /robots.txt { log_not_found off; access_log off; allow all; }
        location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                expires max;
                log_not_found off;

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass;


server {
#    listen 443 ssl;

# location /xmlrpc.php {
#      deny all;
#    }

#    rewrite ^(.*[^/])$ $1/ permanent;
    return 301$request_uri;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot



Submit an 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.

Accepted Answer

Hi there @ozwiz,

What you could do in this case is add your Droplet’s IP address to your server_name list. So it would look like this:

        server_name your_server_ip_address;

However what I could suggest is rather than doing this, it would be better to create a redirect so that if anyone visits the IP address of your Droplet they would get redirected to your domain name instead. I believe that this would be better in terms of SEO.

Hope that this helps! Regards, Bobby