以编程方式更改<Directory / var / www />的AllowOverride

我怎么能(从BASH)改变AllowOverride的<Directory /var/www/>从'None'到'All'?

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

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

但是,我的000-默认文件有其他的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/> ps上设置我在Ubuntu-Server 8.04上。

从无更改为全部:

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