1、使用httpd的前提
设置防火墙状态:
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
注意:systemctl start/restart/enable/disable/stop/status/reload的区别
设置selinuxs安全上下文
[root@localhost ~]
[root@localhost ~]
查看状态:
[root@localhost ~]
Aug 31 03:35:09 localhost.localdomain httpd[7374]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
#httpd:无法使用localhost.localdomain可靠地确定服务器的完全限定域名。 全局设置“ServerName”指令以禁止显示此消息
排错:
? 编辑httpd的主配置文件:vim /etc/httpd/conf/httpd.conf
? 将ServerName 改成0.0.0.0:80
? 重启服务
? 看状态显示正常
测试:
? 在客户端:curl http://ip地址,curl -I可以查看http报文信息
? 通过浏览器访问http://ip地址
例如: 1.安装httpd,并将访问apache服务器的首页修改为hello.html, 且内容为: “My Home Page is hello”
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
[root@localhost conf]
httpd.conf magic
[root@localhost conf]
<IfModule dir_module>
DirectoryIndex home.html
</IfModule>
[root@localhost conf]
[root@localhost conf]
2.虚拟主机:虚拟两台主机ip为100,200, 对应访问目录:/www/ip/100, /www/ip/200 并创建首页文件index.html
[root@localhost conf.d]
[root@localhost conf.d]
[root@localhost conf.d]
[root@localhost conf.d]
[root@localhost conf.d]
[root@localhost conf.d]
<Directory /www/ip>
AllowOverride none
Require all granted
</Directory>
<VirtualHost 192.168.189.100:80>
DocumentRoot "/www/ip/100"
</VirtualHost>
<VirtualHost 192.168.189.200:80>
DocumentRoot "/www/ip/200"
</VirtualHost>
[root@localhost conf.d]
[root@localhost conf.d]
3.配置不同端口的虚拟主机访问apache服务器
[root@localhost conf.d]
<Directory /www/ip>
AllowOverride none
Require all granted
</Directory>
Listen 9999
Listen 10000
<VirtualHost 192.168.189.100:9999>
DocumentRoot "/www/ip/100"
</VirtualHost>
<VirtualHost 192.168.189.200:10000>
DocumentRoot "/www/ip/200"
</VirtualHost>
[root@localhost conf.d]
|