I've installed nginx 1.1.19 on Ubuntu 12.04 on my local machine and kept the default /etc/nginx/nginx.conf
except for changing the user directive.
/etc/nginx/nginx.conf
user nginx www-data;
worker_processes 4;
pid /var/run/nginx.pid;
...
I want to make a simple static site work with the web root in my user directory (Lets say my username is 'ubuntu'). Here's the configuration for my test site.
/etc/nginx/sites-available/test-site
server {
#listen 80; ## listen for ipv4; this line is default and implied
#listen [::]:80 default ipv6only=on; ## listen for ipv6
root /home;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
Now obviously puts all my files in the web root so I would NOT put this on a real server, but this illustrates my point. If I create a simple webpage at /home/index.html (not inside my ubuntu user folder), I can access the page at http://localhost/
This WORKS just fine. Now I want to simply put the web root INSIDE by user folder. So in /etc/nginx/sites-available/test-site I change the root directive to be `root /home/ubuntu;. I recreate the symlink to test-site, move /home/index.html to /home/ubuntu/index.html and stop and start the nginx server. Now I get the 403 Forbidden error.
My first suspicion was that this was a permissisons problem. However, when I run ls -al index.html
I see
-rw-r--r-- 1 nginx www-data 183 Aug 12 13:13 index.html
which looks right to me? Even running chmod 777 /home/ubuntu/index.html so that the permissions are
-rwxrwxrwx 1 nginx www-data 183 Aug 12 13:13 index.html
does not help. /etc/init.d/nginx configtest
does not produce any errors either and I'm sure the symlink in /etc/
So I've been at this for a few hours and I'm now wondering what is so special about my user directory that I cannot serve anything inside of it? Ubuntu encrypts home directories these days? Could that be the problem? I also have this issue on an EC2 Ubuntu 12.04 instance (don't know if user directories are encrypted there)