如果我的VirtualHost中指定了DocumentRoot,是否需要指定一个<Directory>?

我使用了一个稍微默认的VirtualHost文件,我之前configuration了一个(之前我对这个东西是如何工作的有很多知识),而且我不确定我应该保留什么。 我不想仅仅尝试一些东西,因为设置一个虚拟机,所有这些东西都是麻烦的,而且当前的configuration是在生产环境中,所以反复试验并不是真正的select。 这里是文件,更改名称以保护无辜:

<VirtualHost *:80> ServerAdmin [email protected] ServerName www.my.hostname ServerAlias my.hostname DocumentRoot /var/www/mysite <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/mysite> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog ${APACHE_LOG_DIR}/access.log combined LogFormat "%t %T/%D \"%r\" %>s %b" mysitelog CustomLog ${APACHE_LOG_DIR}/mysite.access.log mysitelog Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> 

我的问题是:

  1. 我应该摆脱<Directory />块吗? 它在$APACHE_HOME/conf.d/security指定,注释:“这当前违反了某些Web应用程序Debian软件包的configuration。 我应该取消注释这个版本,并从我的虚拟主机中删除一个?

  2. 这只是PHP,所以我猜测没有理由保持CGI块和别名。

  3. 我猜我也可以摆脱doc东西。 我甚至不确定那是什么,所以如果你能解释在“正常”设置中会用到什么,那么奖励点(不是真的)。

所以,假设我正确的想法,我的新的虚拟主机文件可能是这样的:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.my.hostname ServerAlias my.hostname DocumentRoot /var/www/mysite <Directory /var/www/mysite> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined CustomLog ${APACHE_LOG_DIR}/access.log combined LogFormat "%t %T/%D \"%r\" %>s %b" mysitelog CustomLog ${APACHE_LOG_DIR}/mysite.access.log mysitelog </VirtualHost> 

任何其他技巧是非常受欢迎的。 谢谢! 请让我知道是否需要我的configuration更多的信息!

我应该摆脱<Directory />块吗?

当然! 这绝对是您可以在服务器级而不是在虚拟主机中处理的东西。

这只是PHP,所以我猜测没有理由保持CGI块和别名。

核武器

我猜我也可以摆脱文件的东西。

核武器 在那里,您可以使用新安装的Web服务器来浏览系统的文档。 这是一个可爱的例子,但在我看来,它不属于默认的configuration文件。

在你build议的configuration文件:看起来不错! 我build议的一个build议是,如果你不使用.htaccess文件,将你的目录块中的AllowOverride All改为AllowOverride None如果你使用的是.htaccess文件,我build议你把它们改成nuit,目录块。 ( 这里详细说明为什么我这么说 )