Apache/2.4.18 (Ubuntu) Ubuntu 16.04
这是我的000-default.conf文件:
<VirtualHost *:80> ServerAdmin [email protected] ServerName myserver.net DocumentRoot /home/utils/rails/public <Directory /home/utils/rails/public> AllowOverride all Options -MultiViews Require all granted </Directory> LogLevel warn ErrorLog ${APACHE_LOG_DIR}/myserver.net_error.log CustomLog ${APACHE_LOG_DIR}/myserver.net_access.log combined </VirtualHost>
/ home / utils / rails / public目录的文件设置被设置为0755
我正进入(状态:
Forbidden You don't have permission to access / on this server.
这是我第一次碰到这个。 有任何想法吗?
在您的虚拟主机中设置目录为您的文档,如果您是pipe理员,请勿使用.htaccess,因为您可以看到,如果您不完全知道自己在做什么,会导致混淆和错误,所以真正的答案是,将目录设置为documentroot并设置allowoverride none,控制虚拟主机内的访问,全部在一个地方以便于检查。
<VirtualHost *:80> ServerAdmin [email protected] ServerName myserver.net DocumentRoot "/home/utils/rails/public" <Directory "/home/utils/rails/public"> AllowOverride None Require all granted </Directory> LogLevel warn ErrorLog ${APACHE_LOG_DIR}/myserver.net_error.log CustomLog ${APACHE_LOG_DIR}/myserver.net_access.log combined </VirtualHost>
如果您想知道<Directory /> 属于哪个属性 ,它就属于服务器configuration ( 或全局configuration,虚拟主机之外 ), 应该设置为全部禁止 。 否则,你实际上是让所有人访问你的整个文件系统。
我也删除了你的用于mod_negotation的IfModule,因为禁用multiviews与没有这个function是一样的,所以Ifmodule mod_negotiation禁用multiviews是没有意义的。
以下解决了这个问题:
<VirtualHost *:80> ServerAdmin [email protected] ServerName myserver.net DocumentRoot "/home/utils/rails/public" <Directory "/home/utils/rails/public"> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> AllowOverride None Require all granted </Directory> LogLevel warn ErrorLog ${APACHE_LOG_DIR}/myserver.net_error.log CustomLog ${APACHE_LOG_DIR}/myserver.net_access.log combined </VirtualHost>
关键是:
Require all granted
这是自Apache 2.4以来使用。 其他指令并不是访问问题的关键,但我有他们不允许.htaccess指令( ALlowOverride )和处理Multiviews
设置权限为0755的作品,并不需要改变
*修正目录path未复制的错字