httpd配置三种虚拟主机

微信扫一扫,分享到朋友圈

httpd配置三种虚拟主机

.在httpd配置完成的情况下进行一下操作

#提前做一个软连接
[[email protected] ~]# echo  "export PATH=/usr/local/apachectl/bin:$PATH"  >  /etc/profile.d/httpd.sh
[[email protected] ~]# . /etc/profile.d/httpd.sh
[[email protected] ~]# apachectl start
#设置是否能访问
[[email protected] ~]# vim /etc/httpd24/httpd.conf
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory "/usr/local/apache/htdocs/whb">
<RequireAll>
Require all denied      #禁止任何服务器访问
Require ip 192.168.86.137       #只允许访问192.168.86.137
</RequireAll>
</Directory>
相同IP相同端口不同域名
[[email protected] ~]# 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
[[email protected] ~]# vim /etc/httpd24/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin [email protected]
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
</VirtualHost>     #复制这些代码为参照模板
[[email protected] ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>      #编译后的样式
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
#*是代表所有ip,80代表所有端口
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
[[email protected] ~]# cd /usr/local
[[email protected] apache]# cd htdocs/
[[email protected] htdocs]# ls
index.html
[[email protected] htdocs]# mkdir 123 456
[[email protected] htdocs]# ls
123  456  index.html
#最好把他们的属主和属组都改为apache
[[email protected] htdocs]# chown -R apache.apache 123
[[email protected] htdocs]# chown -R apache.apache 456
[[email protected] 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
[[email protected] htdocs]# ls
123  456  index.html
[[email protected] htdocs]# cd 123/
[[email protected] 123]# ls
[[email protected] 123]# echo "I miss you" > index.html
[[email protected] 123]# cd ..
[[email protected] htdocs]# cd 456/
[[email protected] 456]# echo "I LOVE YOU" > index.html
[[email protected] 456]# apachectl -t
Syntax OK
[[email protected] 456]# apachectl restart
不同ip相同端口:
[[email protected] 456]# vim /etc/httpd24//httpd.conf
<VirtualHost 192.168.86.137:80>
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost 192.168.86.131:80>
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
#添加ip
[[email protected] 456]# ip addr add 192.168.86.131/24 dev ens33
[[email protected] htdocs]# ip a
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> 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
[[email protected] 456]# apachectl -t
Syntax OK
[[email protected] 456]# apachectl restart
相同IP不同端口:
[[email protected] htdocs]# vim /etc/httpd24//httpd.conf
<VirtualHost 192.168.86.137:80>
DocumentRoot "/usr/local/apache/htdocs/123"
ServerName whb.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
<VirtualHost 192.168.86.137:81>
DocumentRoot "/usr/local/apache/htdocs/456"
ServerName aaa.example.com
ErrorLog "logs/error_log"
CustomLog "logs/access_log" common
</VirtualHost>
:/Listen
Listen 80
Listen 81
[[email protected] htdocs]# apachectl -t
Syntax OK
[[email protected] htdocs]# apachectl restart

httpd配置三种虚拟主机

原文地址:https://blog.51cto.com/14763231/2483861

spring-cloud-gateway过滤器实践

上一篇

linux入门系列20--Web服务之LNMP架构实战

下一篇

你也可能喜欢

httpd配置三种虚拟主机

长按储存图像,分享给朋友