You have to use absolute path in root
directive. So use:
root /usr/share/nginx/html/data/www;
Also nginx does not reload if it sees errors in config, so check your config with nginx -t
.
Question
I am new to nginx and i tried a lot to figure out what is going wrong but couldnt.
First, I added a html file "welcome.html"
in /usr/share/nginx/html/data/www
. Then I could access it in my browser using, localhost/data/www/welcome.html
.
Then I added the following code in the nginx.conf file in /etc/bin/nginx/nginx.conf:
server
{
location /
{
root /data/www;
}
}
After that, i reloaded the configurations using, sudo nginx -s reload. This gave no errors!
But, after this I tried to access my file using "localhost/welcome.html"
but it shows an error 404! Although I can still access the file at "localhost/data/www/welcome.html"
. Please tell me where am I going wrong ?
Solution
You have to use absolute path in root
directive. So use:
root /usr/share/nginx/html/data/www;
Also nginx does not reload if it sees errors in config, so check your config with nginx -t
.