标签:glob listen lob pre miss cto 提前 vhost ocs
.在httpd配置完成的情况下进行一下操作
#提前做一个软连接
[root@localhost ~]# echo "export PATH=/usr/local/apachectl/bin:$PATH" > /etc/profile.d/httpd.sh
[root@localhost ~]# . /etc/profile.d/httpd.sh
[root@localhost ~]# apachectl start
#设置是否能访问
[root@localhost ~]# vim /etc/httpd24/httpd.conf
AllowOverride none
Require all denied
Require all denied #禁止任何服务器访问
Require ip 192.168.86.137 #只允许访问192.168.86.137
相同IP相同端口不同域名
[root@localhost ~]# find / -name *vhosts.conf
/etc/httpd24/extra/httpd-vhosts.conf
/etc/httpd24/original/extra/httpd-vhosts.conf
/root/httpd-2.4.38/docs/conf/extra/httpd-vhosts.conf
[root@localhost ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
#复制这些代码为参照模板
[root@localhost ~]# vim /etc/httpd24/httpd.conf
#编译后的样式
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
#*是代表所有ip,80代表所有端口
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
[root@localhost ~]# cd /usr/local
[root@localhost apache]# cd htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir 123 456
[root@localhost htdocs]# ls
123 456 index.html
#最好把他们的属主和属组都改为apache
[root@localhost htdocs]# chown -R apache.apache 123
[root@localhost htdocs]# chown -R apache.apache 456
[root@localhost htdocs]# ll
总用量 4
drwxr-sr-x 2 apache apache 6 3月 30 14:40 123
drwxr-sr-x 2 apache apache 6 3月 30 14:40 456
-rw-r--r-- 1 root root 45 6月 12 2007 index.html
[root@localhost htdocs]# ls
123 456 index.html
[root@localhost htdocs]# cd 123/
[root@localhost 123]# ls
[root@localhost 123]# echo "I miss you" > index.html
[root@localhost 123]# cd ..
[root@localhost htdocs]# cd 456/
[root@localhost 456]# echo "I LOVE YOU" > index.html
[root@localhost 456]# apachectl -t
Syntax OK
[root@localhost 456]# apachectl restart
不同ip相同端口:
[root@localhost 456]# vim /etc/httpd24//httpd.conf
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
#添加ip
[root@localhost 456]# ip addr add 192.168.86.131/24 dev ens33
[root@localhost htdocs]# ip a
2: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:f8:ef:15 brd ff:ff:ff:ff:ff:ff
inet 192.168.86.137/24 brd 192.168.86.255 scope global dynamic ens33
valid_lft 1065sec preferred_lft 1065sec
inet 192.168.86.131/24 scope global secondary ens33
valid_lft forever preferred_lft forever
[root@localhost 456]# apachectl -t
Syntax OK
[root@localhost 456]# apachectl restart
相同IP不同端口:
[root@localhost htdocs]# vim /etc/httpd24//httpd.conf
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
:/Listen
Listen 80
Listen 81
[root@localhost htdocs]# apachectl -t
Syntax OK
[root@localhost htdocs]# apachectl restart
httpd配置三种虚拟主机
标签:glob listen lob pre miss cto 提前 vhost ocs
原文地址:https://blog.51cto.com/14763231/2483861