我在本地机器上的Ubuntu 12.04上安装了nginx 1.1.19,除了更改用户指令外,还保留了默认的/etc/nginx/nginx.conf 。
/etc/nginx/nginx.conf
user nginx www-data; worker_processes 4; pid /var/run/nginx.pid; ...
我想用我的用户目录中的web根目录做一个简单的静态网站工作(假设我的用户名是'ubuntu')。 这是我的testing网站的configuration。
在/ etc / nginx的/网站可用/testing现场
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 } }
现在显然把我所有的文件放在web根目录下,所以我不会把它放在真正的服务器上,但是这说明了我的观点。 如果我在/home/index.html(不在我的ubuntu用户文件夹内)创build一个简单的网页,我可以访问http://localhost/
这工作就好了。 现在我想简单地把用户文件夹的网页内核INSIDE。 所以在/ etc / nginx / sites-available / test-site中,我把root指令改为`root / home / ubuntu ;. 我重新创build符号链接到testing站点,将/home/index.html移动到/home/ubuntu/index.html并停止并启动nginx服务器。 现在我得到了403 Forbidden的错误。
我的第一个怀疑是这是一个许可问题。 但是,当我运行ls -al index.html我看到
-rw-r--r-- 1 nginx www-data 183 Aug 12 13:13 index.html
这对我来说是正确的? 即使运行chmod 777 /home/ubuntu/index.html,以便权限
-rwxrwxrwx 1 nginx www-data 183 Aug 12 13:13 index.html
没有帮助。 /etc/init.d/nginx configtest也不会产生任何错误,而且我确定/etc/
所以我已经在这个几个小时了,现在我想知道我的用户目录有什么特别之处,我不能在里面提供任何东西? Ubuntuencryption主目录这些天? 这可能是问题吗? 我在EC2 Ubuntu 12.04实例上也有这个问题(不知道用户目录是否在那里encryption)
因此,Ubuntu 12.04中用户主目录的默认权限似乎是700. Nginx需要具有读权限,即应该提供的文件,并且在从根目录到服务文件的path中的每个父目录中都具有执行权限。
您可以通过运行为您的用户目录提供这些权限
chmod 701 user_home
您还可以使用755,这是许多系统上主目录上的默认权限设置。
只要nginx运行的用户/组(如nginx.conf中定义的那样)对所有要提供服务的文件具有“读取”权限,Web根目录/文件就可以属于www-data用户或普通个人用户执行所有Web根目录的权限。
我只是将我的web根目录中的所有目录设置为由我的用户帐户拥有,并且具有权限755,并且我将web根目录中的所有文件设置为具有权限664,因为这些是我的机器上的默认值。
Ex. drwxr-x--x becomes 751.
忽略第一个字符(d代表目录, – 代表文件等)。 其余9个字符构成一个二进制三元组,其中任何非短划线字符是1,短划线是0。
So drwxr-x--x becomes rwxr-x--x becomes 111 101 001 which is converted to a decimal 751
当我正在处理权限时,我需要进行一次复习。