nginx location root question

Hey everybody, I just bought a linode last night and I ended up installing the Arch Linux flavor. I installed the nginx server succesfully with the pacman package handler. And the server is up and running.

I have a linux/nginx noob question though.

when I set up the nginx.conf file with the documentation found in the linode tutorials it has the root directive set to this :

root   /srv/http/example.com/public;

it works; however I made a directory in my root

/mywebfiles

and changed the root directive appropriately

root   /mywebfiles;

and it gives me a 404 when ever I point to my web address.

Am I missing something here? Am I not allowed to server up files from anywhere else other then the /srv/ directory? or do I need to CHMOD my /mywebfiles/ directory ?

this is most likely a simple issue to an expirienced user.

Thank you for reading.

-Isaac

9 Replies

You need to set the proper location and permissions for your directories. If you created the folder "mywebfiles" in your /root directory, you will need to point it to /root/mywebfiles for it to function properly. You also need to run chown for nginx to access the folder:

chown nginx:nginx -R /root/mywebfiles

Hope that helps!

iWizardPro, thank you! it worked.. for the most part.

however now I am getting a 403 forbidden error.

both of the /root/srv/ and /root/mywebfiles have the same chmod value -> of drwxr-xr-x

the chown command did not work, as I am logged in as root and I don't have a nginx user or group …

what now could be the cause for nginx not being able to access /root/mywebfiles?

/root is a protected directory, you shouldn't let non root users access it.

Try putting your files in /srv (not /root/srv) or somewhere else.

@Jay3ld:

/root is a protected directory, you shouldn't let non root users access it.

Try putting your files in /srv (not /root/srv) or somewhere else.

Thanks for the reply Jay3ld , in taking your advice I have decided to move the folder into the home directory of 'isaac'

/home/isaac/mywebfiles

but I still get the same 403 error :/ I honestly don't mind keeping serving up my site from the srv directory, however this is something simple that should be possible but I cannot get it to work.

Please do try

chown www-data:www-data -R /yourfullpath

You shouldn't have to chown your directories and files to the nginx (or www-data) user. As long as your directories and files are world-readable (which they usually are by default), nginx will have no trouble serving them over the web, no matter who owns them. In fact, it's a potential security risk to have web files owned by the same user as the web server.

Do you have an index.html file in the directory? If there isn't, nginx will keep throwing 403 errors. If you want to use index.php or some other file as the home page, you must make sure that there's an "index" or "try_files" directive that points to the right file.

hybinet, I do have an Index.html file, and try_files directive, for some reason it just doesn't serve up files from any other directory other than the /srv Im completely puzzeled.

Am a newbie like yourself, but have my LEMP up and running (ubuntu server).

I just put all websites in the /srv/www/ directory (default dir for nginx on ubuntu):

/srv/www/site1/

/srv/www/site2/

Owner is main user, in your case this would be isaac, but files are readable by www-data (nginx user on ubuntu). I never used arch linux and am no expert, but if you want more help, could you post your nginx.conf, virtual host config file and nginx error log (and virtual host error log)?

Does anything appear in the error log when you get 403 errors? The error log might contain more detailed information about the problem.

Are you running any sort of access control mechanism (e.g. AppArmor) that restricts server programs to specific directories?

Are you running nginx in a chroot? (Probably not, since nginx can find /srv, but it's still worth looking into.)

If the problem persists and you really really want to put your website files somewhere else,y you could try using symlinks, you know…

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct