如何禁用所有 apache 虚拟主机?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/183115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:50:49  来源:igfitidea点击:

How to disable all apache virtual hosts?

apachevirtualhost

提问by Christian Oudard

I'm writing a shell script to do some web server configuration. I need to disable all currently active virtual hosts. a2dissitedoesn't accept multiple arguments, so I can't do

我正在编写一个 shell 脚本来进行一些 Web 服务器配置。我需要禁用所有当前活动的虚拟主机。a2dissite不接受多个参数,所以我做不到

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

Should I use find? Is it safe to manually delete the symlinks in /etc/apache2/sites-enabled?

我应该使用find吗?手动删除中的符号链接是否安全/etc/apache2/sites-enabled

回答by Rob

ubuntu 12.04lts / ubuntu 16.04lts

ubuntu 12.04lts / ubuntu 16.04lts

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

您只需执行以下操作 [注意:您可能需要 root 权限 sudo a2dissite]

a2dissite *

Or

或者

a2dissite

And it will prompt you for the ones you want to do

它会提示你选择你想做的事情

when you have completely disabled sites restart apache2 server

当您完全禁用站点时,请重新启动 apache2 服务器

sudo systemctl restart apache2

or just reload apache configuration without a full restart:

或者只是在没有完全重启的情况下重新加载 apache 配置:

sudo service apache2 reload

回答by Christian Oudard

After a little more research, I found out that a2dissiteis just a shell script, and it basically just calls rm. So, like other responses, I agree that it is safe to do

经过更多的研究,我发现这a2dissite只是一个 shell 脚本,它基本上只是调用rm. 所以,像其他回应一样,我同意这样做是安全的

rm /etc/apache2/sites-enabled/*

回答by Vinko Vrsalovic

Is your script Debian only? If so, you can safely delete all the symlinks in sites-enabled, that will work as long as all sites have been written correctly, in the sites-available directory.

您的脚本仅适用于 Debian 吗?如果是这样,您可以安全地删除启用了站点的所有符号链接,只要所有站点都已正确写入,就可以在站点可用目录中正常工作。

For example:

例如:

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

will protect you against someone who has actually written a file instead of a symlink in that directory.

将保护您免受实际编写文件而不是该目录中的符号链接的人的侵害。

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

(当然,从 rm 中删除 -i 以获得自动脚本)

回答by Supravat Mondal

To remove the host file just delete it. If you just want to dissablethe site, use

要删除主机文件,只需将其删除。如果您只想禁用该站点,请使用

sudo a2dissite sitename

Restart apache2

重启apache2

sudo /etc/init.d/apache2 reload

Again to remove (delete)it completely from the system,

再次从系统中完全删除(删除)它,

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

I would also disable it first before deleting the file

我也会在删除文件之前先禁用它

回答by Supravat Mondal

You can just delete the symlinks, or move the entire directory away. There is no special database or other metadata besides those links.

您可以删除符号链接,或将整个目录移开。除了这些链接之外,没有特殊的数据库或其他元数据。

回答by Darren Greaves

I never use 'a2dissite ' and always delete and create the links in /etc/apache2/sites-enabled manually so yes, I'd say it's pretty safe.

我从不使用 'a2dissite ' 并且总是手动删除和创建 /etc/apache2/sites-enabled 中的链接,所以是的,我会说它非常安全。

回答by Telvin Nguyen

Here is my workaround, first type:

这是我的解决方法,第一种类型:

# a2dissite(type this command without any argument, it would prompt to ask you choose the next line)

# a2dissite(不带任何参数输入此命令,它会提示您选择下一行)

Your choices are: siteA siteB siteC siteD

Which site(s) do you want to disable (wildcards ok)?

您的选择是:站点A站点B站点C站点D

您要禁用哪个站点(可以使用通配符)?

Now you just copy all of above list of sites (siteA siteB siteC siteD) and paste into as your answer, then Enter.

现在,您只需复制以上所有站点列表(siteA siteB siteC siteD)并粘贴到作为您的答案,然后输入。

The output result would 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 to optional to choose to a long list of names of site should be removed or intact.

这种方法将帮助我们有选择地选择一长串站点名称应该被删除还是完好无损。

回答by Mote

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

您可以编辑 httpd.conf 并删除虚拟主机的包含行(在文件底部)

回答by leppie

Apparently, you can just install the latest Ubuntu ;)

显然,您只需安装最新的 Ubuntu ;)