Centos7搭建http服务器

1.安装

yum –y install httpd

2.配置文件

/etc/httpd/conf/httpd.conf

监听端口默认80

#
#Listen 12.34.56.78:80
Listen 80

HTML文件位置

#
DocumentRoot "/var/www/html"

#

3.查看端口占用情况

firewall-cmd  --query-port=80/tcp
firewall-cmd  --query-port=80/udp

若返回no 则表示80端口未开启

永久开放80端口:

firewall-cmd  --permanent  - -zone=public  - - add-port=80/tcp
firewall-cmd  --permanent  - -zone=public  - - add-port=80/udp
重启防火墙:
firewall-cmd  - -reload

4.创建html文件

在/var/www/html中创建index.html内容为Hello World!

修改index.html的所有者和所属组为apache:

chown apache.apache index.html

5.启动服务

systemctl start httpd

设置开机自启:

systemctlenable httpd

重启服务:

systemctlrestart httpd

6.访问http服务器

curl 172.17.24.170:80

在浏览器中访问

http://172.17.24.170:80

7.问题解决

错误信息:

Forbidden

You don't have permission to access / on this server.

Additionally, a 404 Not Found error was encountered while trying to use anErrorDocument to handle the request.

解决:

<Directory/>
    AllowOverride none
    Require all denied
</Directory>

修改为Require all granted

猜你喜欢

转载自blog.csdn.net/weixin_41661222/article/details/80621372