linux apache ip配置,linux apache虚拟主机配置(基于ip,端口,域名)
配置環(huán)境:
linux版本:Centos6.4
httpd版本:
[[email?protected] init.d]# pwd
/etc/init.d
[[email?protected] init.d]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Oct 19 2017 16:43:38
1,安裝httpd服務
yum install httpd -y
2,關(guān)閉selinux和防火墻
臨時設置selinux為permissive( disabled )狀態(tài)
Enforcing
[[email?protected] ~]# setenforce 0
Permissive
永久修改方法:
[[email?protected] ~]# vim /etc/sysconfig/selinux
SELINUX=permissive
3,關(guān)閉防火墻
service iptables stop
第一種,基于多ip訪問的配置:
1,先把httpd.conf備份一下,以防出錯,可以恢復
httpd.conf的文件路徑(?/etc/httpd/conf )
[[email?protected] conf]# ls
httpd.conf httpd.conf.bak magic
2,如果需要啟用虛擬主機配置,先把中心主機的配置注釋,
#DocumentRoot "/var/www/html"
3,在httpd.conf中,會默認包conf.d目錄中的所有 以.conf結(jié)尾的配置文件
Include conf.d/*.conf
所以,把虛擬主機的配置文件獨立出來放在conf.d目錄下
[[email?protected] httpd]# ls
conf conf.d logs modules run
[[email?protected] httpd]# pwd
/etc/httpd
[[email?protected] httpd]# cd conf.d
[[email?protected] conf.d]# pwd
/etc/httpd/conf.d
[[email?protected] conf.d]# ls
README VirtualHost.conf welcome.conf
VirtualHost.conf 配置文件內(nèi)容:
ServerName www.7mxt.com
DocumentRoot "/www/7mxt.com"
ServerName www.7mxt.net
DocumentRoot "/www/7mxt.net"
我的主機ip是192.168.1.8,添加另一個ip:
ip addr add 192.168.1.2/24 dev eth0
在對應的目錄建立文件:
[[email?protected] www]# tree
.
├── 7mxt.com
│?? └── index.html
└── 7mxt.net
└── index.html
重啟服務: service httpd restart,在瀏覽器中分別用這兩個ip訪問,就能看到對應的頁面
第二種,基于多端口訪問的配置:
1,在VirtualHost.conf中增加一項配置:
ServerName www.7mxt.com
DocumentRoot "/www/7mxt.com"
ServerName www.7mxt.net
DocumentRoot "/www/7mxt.net"
ServerName www.abc.net
DocumentRoot "/www/abc.net"
2,在httpd.conf監(jiān)聽8080端口
Listen 80
Listen 8080
3,/www建立對應的目錄和文件
重啟服務: service httpd restart,在瀏覽器中用http://192.168.1.2:8080/? 就能訪問到abc.net目錄下面的文件index.html內(nèi)容
[[email?protected] www]# tree
.
├── 7mxt.com
│?? └── index.html
├── 7mxt.net
│?? └── index.html
└── abc.net
└── index.html
第三種:基于域名的主機配置
1,NameVirtualHost:指定192.168.1.8:80這個ip地址使用域名解釋
NameVirtualHost 192.168.1.8:80
ServerName www.7mxt.com
DocumentRoot "/www/7mxt.com"
ServerName www.7mxt.org
DocumentRoot "/www/7mxt.org"
ServerName www.7mxt.net
DocumentRoot "/www/7mxt.net"
ServerName www.abc.net
DocumentRoot "/www/abc.net"
2,在對應的目錄下建立文件
[[email?protected] www]# tree
.
├── 7mxt.com
│?? └── index.html
├── 7mxt.net
│?? └── index.html
├── 7mxt.org
│?? └── index.html
└── abc.net
└── index.html
3,在windows host文件中增加主機映射配置
【C:\Windows\System32\drivers\etc】
192.168.1.8 www.7mxt.com
192.168.1.8 www.7mxt.org
4,重啟服務: service httpd restart,分別用域名www.7mxt.com, www.7mxt.org就能訪問到對應的文件內(nèi)容
使用ip: 192.168.1.8返回的是第一個虛擬主機的配置,即:www.7mxt.com對應目錄下面的內(nèi)容
原文:http://www.cnblogs.com/ghostwu/p/7827104.html
總結(jié)
以上是生活随笔為你收集整理的linux apache ip配置,linux apache虚拟主机配置(基于ip,端口,域名)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity光照效果_自发光动态改变并影响
- 下一篇: 配置计算机名及工作组;TCP/IP地址配