13

I have installed nginx on my Ubunut 12.04, I am not able to change the root directory for the nginx,

This is the default nginx configuration file:

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        #root /usr/share/nginx/html;
        root /var/www
        index index.html index.htm;

        server_name localhost;

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

I tried changing root to /var/www/ but some how it doesn't want to change. I tried restarting the nginx but I am not able to change the root directory.

1
  • 2
    Use command nginx -t to check for syntax errors.
    – Alexey Ten
    Jun 11, 2014 at 10:44

2 Answers 2

15

Your configuration is missing the ; at the end of root directive.

Try this:

root /var/www;
1
  • Wow.. you got me there, that works.. thanks for the quick reply :) getting rid of Apache was hurting me.. thanks a lot
    – shrish
    Jun 11, 2014 at 10:40
2
  1. Go to /etc/nginx/sites-available.
cd /etc/nginx/sites-available
  1. Open default.
sudo nano default

You will get something like this, opened on your nano editor:
(I have removed the comments for the simplicity of this answer)

server {
    listen 80 default_server;
    listen [::]:80 default_server;
   
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }
}
  1. Edit the line root /var/www/html; to root /your/specified/path;

  2. Save the file & exit.

  3. Restart nginx

sudo systemctl restart nginx

Now, you should be good to go.

Check the server status and see if its is active (without throwing any error):

sudo systemctl status nginx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .