900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > linux apache ip配置 linux apache虚拟主机配置(基于ip 端口 域名)

linux apache ip配置 linux apache虚拟主机配置(基于ip 端口 域名)

时间:2022-02-15 23:55:11

相关推荐

linux apache ip配置 linux apache虚拟主机配置(基于ip 端口 域名)

配置环境:

linux版本:Centos6.4

httpd版本:

[[emailprotected] init.d]# pwd

/etc/init.d

[[emailprotected] init.d]# httpd -v

Server version: Apache/2.2.15 (Unix)

Server built: Oct 19 16:43:38

1,安装httpd服务

yum install httpd -y

2,关闭selinux和防火墙

临时设置selinux为permissive( disabled )状态

Enforcing

[[emailprotected] ~]# setenforce 0

Permissive

永久修改方法:

[[emailprotected] ~]# vim /etc/sysconfig/selinux

SELINUX=permissive

3,关闭防火墙

service iptables stop

第一种,基于多ip访问的配置:

1,先把httpd.conf备份一下,以防出错,可以恢复

httpd.conf的文件路径(/etc/httpd/conf )

[[emailprotected] conf]# ls

httpd.conf httpd.conf.bak magic

2,如果需要启用虚拟主机配置,先把中心主机的配置注释,

#DocumentRoot "/var/www/html"

3,在httpd.conf中,会默认包conf.d目录中的所有 以.conf结尾的配置文件

Include conf.d/*.conf

所以,把虚拟主机的配置文件独立出来放在conf.d目录下

[[emailprotected] httpd]# ls

conf conf.d logs modules run

[[emailprotected] httpd]# pwd

/etc/httpd

[[emailprotected] httpd]# cd conf.d

[[emailprotected] conf.d]# pwd

/etc/httpd/conf.d

[[emailprotected] conf.d]# ls

README VirtualHost.conf welcome.conf

VirtualHost.conf 配置文件内容:

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

我的主机ip是192.168.1.8,添加另一个ip:

ip addr add 192.168.1.2/24 dev eth0

在对应的目录建立文件:

[[emailprotected] www]# tree

.

├──

│ └── index.html

└──

└── index.html

重启服务: service httpd restart,在浏览器中分别用这两个ip访问,就能看到对应的页面

第二种,基于多端口访问的配置:

1,在VirtualHost.conf中增加一项配置:

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

2,在httpd.conf监听8080端口

Listen 80

Listen 8080

3,/www建立对应的目录和文件

重启服务: service httpd restart,在浏览器中用http://192.168.1.2:8080/ 就能访问到目录下面的文件index.html内容

[[emailprotected] www]# tree

.

├──

│ └── index.html

├──

│ └── index.html

└──

└── index.html

第三种:基于域名的主机配置

1,NameVirtualHost:指定192.168.1.8:80这个ip地址使用域名解释

NameVirtualHost 192.168.1.8:80

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

ServerName

DocumentRoot "/www/"

2,在对应的目录下建立文件

[[emailprotected] www]# tree

.

├──

│ └── index.html

├──

│ └── index.html

├──

│ └── index.html

└──

└── index.html

3,在windows host文件中增加主机映射配置

【C:\Windows\System32\drivers\etc】

192.168.1.8

192.168.1.8

4,重启服务: service httpd restart,分别用域名, 就能访问到对应的文件内容

使用ip: 192.168.1.8返回的是第一个虚拟主机的配置,即:对应目录下面的内容

原文:/ghostwu/p/7827104.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。