CentOS7 搭建 httpd 服务)
1. 搭建步骤
1.1. 安装httpd服务
在centos操作系统下执行shell命令:
yum install httpd -y
1.2. rpm -qi httpd命令查看httpd的版本信息
[root@glusterfs ftp-user2]# rpm -qi httpd
Name : httpd
Version : 2.4.6
Release : 93.el7.centos
Architecture: x86_64
Install Date: Mon 10 Aug 2020 03:35:44 PM CST
……
1.3. 启动http服务
systemctl start httpd.service
1.4. 配置文件 /etc/httpd/conf/ httpd.conf
注意三个参数 Listen 和 ServerName DocumentRoot
-
#Listen 12.34.56.78:80
Listen参数,默认值为80,但为了避免和其他程序冲突,修改为其他值。 -
#ServerName www.example.com:80
ServerName服务器名称和端口号 -
DocumentRoot “/var/www/html”
DocumentRoot参数是需要生成url的文件存放路径。
1.5. 如果http的80端口被占用,修改端口Listen 和ServerName
[root@glusterfs ftp-user2]# netstat -lpn | grep 80 -w
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28592/nginx: master
[root@glusterfs ftp-user2]#
修改端口为其他端口,如7777
#Listen 12.34.56.78:80
Listen 7777
修改ServerName
#ServerName www.example.com:80
ServerName www.55.55.55.101.com:7777
1.5.1 如果还有错,就是https的端口了
修改 /etc/httpd/conf.d/ssh.conf
修改端口号即可
#Listen 443 https
Listen 9999 https
1.6. 搭建完成测试
1.生成index文件输入内容
echo "123 123 123 china " > index.html //生成index文件输入内容
[root@glusterfs ftp-user2]# ll /var/www/html/
total 124
-rw-r--r-- 1 root root 19 Aug 10 17:09 index.html
[root@glusterfs ftp-user2]# cat /var/www/html/index.html
123 123 123 china
[root@glusterfs ftp-user2]#
2.在浏览器输入http://服务器IP:port,看是否能进入HTTP样本网页,如果能进入如下页面,说明httpd服务器搭建成功。
在页面输入:
或者curl测试也可以
[root@glusterfs ftp-user2]# curl http://55.55.55.101:7777
123 123 123 china
[root@glusterfs ftp-user2]#
1.7 curl命令
curl是基于URL语法在命令行方式下工作的文件传输工具,它支持FTP,FTPS,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE及LDAP等协议。
参考:
https://www.cnblogs.com/walkinginthesun/p/9543001.html
https://blog.csdn.net/whell_scl/article/details/94002885