NGINX throws 404 when I visit, and in my error logs it gives

/home/dev/Dropbox/www/index.php" failed (13: permission denied)

I'm not sure why, this only happened when changing my direction to dropbox.

Running ps -ef | grep nginx outputs:

root 11373 5885 0 15:48 pts/0 00:00:00 sudo nano /etc/nginx/sites-available/default 
root 11374 11373 0 15:48 pts/0 00:00:00 nano /etc/nginx/sites-available/default 
dev 11566 3392 0 15:55 ? 00:00:03 gedit /var/log/nginx/error.log 
root 11607 1 0 16:01 ? 00:00:00 nginx: master process /usr/sbin/nginx -g daemon on;master_process on; 
www-data 11608 11607 0 16:01 ? 00:00:00 nginx:
worker process 
www-data 11609 11607 0 16:01 ? 00:00:00 nginx: worker
dev 11715 5885 0 16:16 pts/0 00:00:00 grep --color=auto nginx


Running ls -l /home/dev/Dropbox/www/index.php outputs:

-rw-rw-r-- 1 dev dev 2 Feb 10 15:26 /home/dev/Dropbox/www/index.php
  • What user is nginx running under, and what are the access rights to your index.php ? Said in another way, does the user running nginx have assess to the index.php ? – Soren A Feb 10 '18 at 15:59
  • I haven't given them any access if that's what you mean, its running on the user I created on installation of Ubuntu. – Adam G Feb 10 '18 at 16:01
  • Apparently you dont know how your system is set up .. please run ps -ef | grep nginx and ls -l /home/dev/Dropbox/www/index.php in a terminal, and update your question with the output from both. – Soren A Feb 10 '18 at 16:08
  • I have updated my question. – Adam G Feb 10 '18 at 16:18

Nginx run's as the user www-data. /home/dev/Dropbox/www/index.php is owned by user dev and in group dev,which both has read and write access. Others only have read access. No one has execute rights to the file.

Running chmod +x /home/dev/Dropbox/www/index.php should set execute rights for both owner, group and others .. you will see access rights like -rwxrwxr-x if you do a ls -l on the file again.

Also you might have to configure nginx to allow it to use /home/dev/Dropbox/www/ for data directory.

  • Thanks for the answer although I'm still getting 404. Running ls -l on index.php again returns -rw-rw-r-- 1 dev dev 2 Feb 10 15:26 /home/dev/Dropbox/www/index.php , I also don't understand what you mean by your last sentence, maybe you could explain further. – Adam G Feb 10 '18 at 16:49

Running a website out of any home directory will cause problems. Consider that to get into that directory, a user has to have read and execute ("traverse" for directories) permissions available to them on every folder in the access tree (/home, /home/user/, /home/user/Dropbox/, etc) until you reach the directory for the docroot itself.

This introduces a lot of security risk - if someone happens to hijack the webserver they will be able to traverse into your own home directory data without having to be superuser.

Any websites should be run outside of your actual home directory whether Dropbox'd or not.

You would need to do sudo chmod +rx /home/ /home/user/ /home/user/Dropbox/ /home/user/Dropbox/www/ to properly let things access it, unless you start doing highly customized access rules.

(Note that Dropbox is not a sane way to backup/sync your site, because of the permissions problems it introduces like this...)

  • I receive 'chmod: changing permissions of '/home/': Operation not permitted when trying to do this. – Adam G Feb 10 '18 at 17:08
  • You may need to use sudo with the chmod command. – Thomas Ward Feb 10 '18 at 17:55

Possible, you are using php-fpm with nginx. If this, you need to allow nginx user to write to php-fpm socket.

Edit file

sudo nano /etc/php/7.0/fpm/pool.d/www.conf

uncomment option

;listen.mode = 0600

set new value (it's allow all users write to php-fpm socket)

listen.mode = 0666

Restart php-fpm instance for apply changes

sudo /etc/init.d/php7.0-fpm restart

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.