I find this forum to have a lot of smart people, so I hope this is an okay place to ask!
I have a VPS set up with NGINX that currently has a domain set to be default with a directory in /usr/share/nginx/html.
Let’s say the directory is set to “dir1”
When I try to access another website in another directory for testing, NGINX gives a 404 not found error.
For example, let’s say I wanted to access dir2 (A separate website) by typing: domain.com/dir2 the 404 not found error comes up.
I am new to doing anything related to sysadmin stuff, so if you guys need a specific config file for me to post, please let me know.
Thanks.
So your websites are under
/usr/share/nginx/html/dir1 which works
/usr/share/nginx/html/dir2 which does not work?
Or is the working website in /usr/share/nginx/html/. directly?
What are the directory and file permissions (l s -lah) is the ngnix user permitted to access the subfolder and files in question?
Correct, /usr/share/nginx/html/dir1 etc is the way it is.
The website is a sub-directory in html, not directly inside it. As is all the others.
When running l s -lah I see a mish mash of www-data and root owning the directories. That's my fault.
The dir1 that works is owned by www-data. There are two other directories owned by www-data that have that 404 not found error.
So does that mean a user named nginx needs to have permissions?
I did not know which user name your ngnix is running under; In your case it is www-data and the group www-data
So that ngnix can serve that files and folders via http and https it has to at least be able to read them; a folder or file that is owned by root:root can't be accessed by ngnix.
Make sure that the files themselves belong to www-data or at least the group www-data has read access.
So when you l s -lah the files should either be r--r----- www-data:www-data or rw-rw---- root:www-data or www-data:root should also work ...
tl;dr make sure your webserver ngnix (running as user www-data) can access the files its supposed to serve
And make sure that the server [] block(s) contain the directory where you are hosting from.
1 Like