How to disable all apache virtual hosts?

I am writing a shell script to do some web server configuration. I need to disable all active virtual hosts. a2dissite does not accept multiple arguments, so I cannot execute

 a2dissite `ls /etc/apache2/sites-enabled` 

Should I use find ? Is it possible to manually delete symbolic links in /etc/apache2/sites-enabled ?

+6
apache virtualhost
source share
9 answers

Just your Debian script? If this is the case, you can safely remove all symbolic links in permitted sites that will work until all sites are correctly written in the directory accessible to sites.

For example:

  find /etc/apache2/sites-enabled/ -type l -exec rm -i "{}" \; 

protects you from who actually wrote the file instead of a symlink in this directory.

(remove -i from rm for an automatic script, of course)

+9
source share

After a little research, I found that a2dissite is just a shell script, and it basically just calls rm . So, like the other answers, I agree that it’s safe to do

 rm /etc/apache2/sites-enabled/* 
+11
source share

ubuntu 12.04lts / ubuntu 16.04lts

You can simply do the following [NB: you may need root permission sudo a2dissite]

 a2dissite * 

or

 a2dissite 

And he will offer you the ones you want to make

when you have completely disabled the sites, restart the apache2 server

sudo systemctl restart apache2

+7
source share

You can simply delete symbolic links or move the entire directory. There is no special database or other metadata other than these links.

+2
source share

I never use 'a2dissite' and always delete and create links in / etc / apache 2 / sites-enabled manually, so yes, I would say that it is pretty safe.

+1
source share

To delete a host file, simply delete it. If you just want to sort the site, use

 sudo a2dissite sitename 

Restart apache2

 sudo /etc/init.d/apache2 reload 

Again remove (delete) completely from the system,

 sudo rm /etc/apache2/sites-available/sitename 

I would also disable it before deleting the file

+1
source share

Here is my workaround, first type:

# a2dissite (enter this command without any arguments, it will prompt you to select the next line)

Your options: siteA siteB siteC siteD

Which site do you want to disable (wildcards in order)?

Now you just copy the entire list of sites above ( siteA siteB siteC siteD ) and paste your answer into it, then press Enter.

The output will be:

 removing dangling symlink /etc/apache2/sites-enabled/siteA.conf removing dangling symlink /etc/apache2/sites-enabled/siteB.conf removing dangling symlink /etc/apache2/sites-enabled/siteC.conf removing dangling symlink /etc/apache2/sites-enabled/siteD.conf 

This approach will help us selectively choose a long list of site names that should be deleted or not.

0
source share

you can edit httpd.conf and remove the include line for virtual hosts (at the bottom of the file).

-one
source share

Apparently you can just install the latest version of Ubuntu;)

-3
source share

All Articles