首页 > 技术文章 > apache服务

zhengmengfei 2018-03-06 18:57 原文

1、搭建apache服务步骤

①准备环境(关闭防火墙service iptables stop,关闭selinux-setenforce 0,配置ip地址)

②装软件包yum install httpd -y

③修改配置文件vim /etc/httpd/conf/httpd.conf

vim /etc/httpd/conf/httpd.conf    //编辑主配置文件
ServerRoot "/etc/httpd"             //设置Apache的主目录
Timeout 120                             //设置请求超时
Listen 80                                  //设置监听端口---重要
ServerAdmin root@sales.com          //设置管理员邮箱
ServerName 192.168.0.3:80           //设置主机或IP
DocumentRoot "/var/www/html"      //设置Apache文档目录---文档根目录--重要
DirectoryIndex index.html               //设置主页文件
AddDefaultCharset GB2312            //设置网站编码

④启动服务

使用service httpd stop可以停止httpd

使用service httpd start 可以启动httpd

使用service httpd restart 可以重启httpd

⑤测试

2、apache服务提供网页服务

3、cd /var/www/html目录中新增a.txt文件并填写内容

4、重启服务service httpd restart

5、访问http://IP地址:监听端口/a.txt

浏览器默认端口号80

默认访问文件index.html,即http://IP地址:监听端口/

推荐阅读