apache2配置访问软连接(Symbolic link not allowed or link target not accessible问题解决)

问题:在apache2的默认访问目录下添加软连接问题,无法访问,提示403错误。

apache2配置访问软连接(Symbolic link not allowed or link target not accessible问题解决)_第1张图片

apache的日志报错提示:

apache2配置访问软连接(Symbolic link not allowed or link target not accessible问题解决)_第2张图片

测试在/var/www/html目录里面软连接访问:
1.需要配置apache2.conf:

    Options Indexes FollowSymLinks  ##FollowSymLinks这个参数 Follow Symbolic Links,设置允许软连接到其他目录
    AllowOverride None
    Require all granted

2.建立软连文件:
lrwxrwxrwx 1 root root    33 May 10 16:50 1.txt -> /root/test/learngit/echo_test.txt
lrwxrwxrwx 1 root root    18 May 10 18:55 2.txt -> /home/zrj/test.txt
此时1.txt访问提示403 forbidden;2.txt能正常访问打开
原因在于软连指向的目录,需要开放x权限:
root@zrj-debian:/var/www/html# ll -d /home/ /root /home/zrj/ /root/test/ /root/test/learngit/
drwxr-xr-x  3 root root 4096 Feb 13 17:03 /home/
drwxr-xr-x 19 zrj  zrj  4096 May 10 17:55 /home/zrj/
drwx------  8 root root 4096 May 10 19:00 /root
drwxr-xr-x  6 root root 4096 May  6 17:32 /root/test/
drwxr-xr-x  4 root root 4096 May  8 18:55 /root/test/learngit/
问题在于/root目录其他用户没有x权限,无法访问(Apache2允许时使用www用户),软连指向的每一层目录都需要给X权限。
3.添加权限给其他用户chmod o+x /root/,之后1.txt能正常访问。

 

4.感谢老外的帮助https://unix.stackexchange.com/a/468113/352306,更要怪自己sb到软连到/root系统目录的文件,一般应该新建项目的专用目录操作,可避免对系统目录及文件的安全隐患。

你可能感兴趣的:(apache2)