Changing Nginx root is not working

I have created a LEMP stack ubuntu server on digital ocean and cannot get it to point to my application.

When i go to my servers IP address it goes to an index.php file inside /var/www/html however I want it to point to /var/www/itom/public.

This is my nginx config file

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

    root /var/www/itom/public;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name 138.68.135.117;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

I have restarted nginx with

service nginx restart

Any ideas guys?

Your root needs to reside in a location stanza. In your case it should look like:

location / {
    root   /var/www/itom/public;
    index  index.php index.html index.htm index.nginx-debian.html;
}

Your

try_files $uri $uri/ =404;

does not need to be in the location stanza

Hope this helps.

Your Nginx configuration looks mostly correct, but here are a few things to check:

  1. Remove default_server: Change listen 80 default_server; to just listen 80; if other configurations might be overriding this one.
  2. Permissions: Ensure that the /var/www/itom/public directory and its files have the correct permissions for Nginx to access them (www-data user/group).
  3. Clear Browser Cache: Clear your browser cache or try accessing the IP in incognito mode to rule out caching issues.
  4. Nginx Config Test: Run sudo nginx -t to check for syntax errors before restarting Nginx.
  5. Restart Nginx: Make sure to restart Nginx with sudo systemctl restart nginx.