醉梦半醒的博客

apache基于多ip的虚拟主机配置+文件服务器和账号密码

字数统计: 242阅读时长: 1 min
2019/05/14 Share

当前ip:172.19.16.219/24
添加两个ip:ip addr add 172.19.16.220/24 dev eth0
ip addr add 172.19.16.221/24 dev eth0

在/var/ww/html/下创建web1,web2,web3目录
配置/etc/httpd/conf/httpd.conf
注释掉#DocumentRoot “/var/www/html”
<VirtualHost 172.19.16.219:8080>
ServerName web1.zmbxzrq.com
DocumentRoot “/var/www/html/web1”
<Directory “/var/www/html/web1”>
Options Indexes //web1启用目录浏览
AllowOverride None
AuthType Basic
AuthName “Administator private”
AuthUserFile “/etc/httpd/conf.d/.htpasswd”
Require user admin
</Directory>
</VirtualHost>

<VirtualHost 172.19.16.220:8080>
ServerName web2.zmbxzrq.com
DocumentRoot “/var/www/html/web2”
<Directory “/var/www/html/web2”>
Options None
AllowOverride None
AuthType Basic
AuthName “Administator private”
AuthUserFile “/etc/httpd/conf.d/.htpasswd”
Require user admin
</Directory>
</VirtualHost>

<VirtualHost 172.19.16.221:8080>
ServerName web3.zmbxzrq.com
DocumentRoot “/var/www/html/web3”
<Directory “/var/www/html/web3”>
Options None
AllowOverride None
AuthType Basic
AuthName “Administator private”
AuthUserFile “/etc/httpd/conf.d/.htpasswd”
Require user admin
</Directory>
</VirtualHost>

在/etc/httpd/conf.d/下创建密码本htpasswd -c -m /etc/httpd/conf.d/.htpasswd admin

注释掉/etc/httpd/conf.d/welcome.conf全部内容

CATALOG