以编程方式更改 AllowOverride

以编程方式更改 AllowOverride

我如何以编程方式(使用 BASH)将 AllowOverride<Directory /var/www/>从“无”更改为“全部”?

而不必手动编辑/etc/apache2/sites-enabled/000-default

通常我可以用 sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/sites-enabled/000-default

但是我的 000-default 文件有其他我不想更改的 AllowOverride 指令:

NameVirtualHost *
<VirtualHost *>
 ServerAdmin webmaster@localhost

 DocumentRoot /var/www/
 <Directory />
  Options FollowSymLinks
  AllowOverride None
 </Directory>
 <Directory /var/www/>
  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 /var/log/apache2/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/access.log combined
 ServerSignature On

    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>

例如,我不希望 AllowOverride 开启/usr/share/doc/usr/lib/cgi-bin

我只想在<Directory /var/www/> Ubuntu-Server 8.04 上进行设置。

答案1

要从“无”更改为“全部”,请执行以下操作:

awk '/<Directory \/var\/www\/>/,/AllowOverride None/{sub("None", "All",$0)}{print}'

相关内容