一、配置服务器监听IP及端口
- 注释主配置文件"监听IP及端口"部分
bash
cd /etc/httpd/conf
cp httpd.conf httpd.conf.bak
vim httpd.conf
可以在普通模式下搜索Listen关键字
bash
:/Listen
按n键继续向后搜索
- 在/etc/httpd/conf.d中新建子配置文件port.conf:
bash
touch /etc/httpd/conf.d/port.conf
echo "Listen 81" > /etc/httpd/conf.d/port.conf
或
bash
touch /etc/httpd/conf.d/port.conf
echo "Listen 192.168.209.137:81" > /etc/httpd/conf.d/port.conf
- 重启加载httpd的配置文件
bash
systemctl reload httpd
- 防火墙添加81端口
bash
firewall-cmd --zone=public --add-port=81/tcp --permanent
firewall-cmd --reload
- curl命令访问81端口
bash
curl 127.0.0.1:81
或
bash
curl 192.168.209.137:81 #换成自己的IP
二、配置主页面
- 新建index.html测试页面
bash
cd /var/www/html
rm -rf index.html
echo "hello,openEuler" > index.html
cat index.html
- 访问测试
bash
curl 127.0.0.1:81
三、配置主页面存放目录(配置网站根目录)
- 更改根目录
bash
mkdir /home/source
mv /var/www/html/index.html /home/source/
echo 'DocumentRoot "/home/source"'> /etc/httpd/conf.d/source.conf
- 配置目录访问权限
bash
vim /etc/httpd/conf.d/source.conf
添加如下内容:
bash
<Directory "/home/source">
AllowOverride None
#Allow open access:
Require all granted
</Directory>
bash
systemctl reload httpd
curl 127.0.0.1:81