15053971836 注册 / 登录

apache添加多个网站

时间: 阅读:132
apache添加多个网站

最佳回答

無畏

無畏

2023-01-13 05:26:16

ubuntu server 12.04中apache添加多个网站其实不难,首先先看一个例子,我们先执行以下命令打开配置文件
sudo nano /etc/apache2/sites-available/default,然后你将看到如下实例,按照下面的例子配置就可以了
ServerName localhost
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/websitefile
<Directory />
Options FollowSymLinks
AllowOverride all
#AllowOverride None
</Directory>
<Directory /var/www/websitefile>
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

CustomLog ${APACHE_LOG_DIR}/access.log combined

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>

最新回答共有2条回答

  • 临沂网站建设
    回复
    2023-01-13 07:07:19

    最简单高效的方法如下:
    1. 先打开Apache的配置文件httpd.conf,在这个文件,
    找到这句:“#Include etc/extra/httpd-vhosts.conf”
    (根据安装路径不同,上面的路径会略有不同)
    把前面的#曲调,即开启了使用虚拟主机的功能;
    2. 在httpd-vhosts.conf中进行虚拟主机的配置操作;也可以在httpd.conf直接写入配置,但是
    不建议这么做;
    3. 打开httpd-vhosts.conf文件,找到NameVirutalHost *:80,这句话的含义是制定这个主机的
    IP地址和端口号;
    4. 关键的virtualhost配置,在NameVirutalHost *:80的下面;
    注意事项:Apache在接受请求时,首先会默认第一个VirtualHost,然后再匹配其他虚拟主
    机,如果没有匹配的,就是第一个VirtualHost起作用。故,在httpd.conf中,将
    <Dicrectory />(这个是所有目录的默认配置)和<Direcotry/opt/lampp/htdocs>的权限,
    都默认设置为deny from all。
    5. virtualhost配置实例:
    <VirtualHost*:80>
    ServerName *
    DocumentRoot </opt/lampp/htdocs/guest>
    <Directory /opt/lampp/htdocs/guest>
    Order deny,allow
    Allow from all
    </Dire