南飓风 发表于 2025-1-6 13:41:20

linux搭建网页web假造主机

目次
网站服务预备工作
(1)设置IP地址 172.25.0.11/24
(2)设置当地dnf源
(3)设置主机名 node1.example.com
(4)关闭防火墙
(5)SELinux设置强制模式
物理机预备工作
假造机操作
(1)安装软件包
(2)编写首页文件
(3)启动服务并且设置开机自启(每次修改完设置文件都需重新启动)
增补:
(1)修改设置文件内容说明
创建文件部署web站点
网问权限控制页文件访
网站服务预备工作

假造机(假造机恢复到初始状态)
(1)设置IP地址 172.25.0.11/24

   # nmcli connection modify ‘ens160’ ipv4.method manual ipv4.addresses 172.25.0.11/24 connection.autoconnect yes
# nmcli connection up ens160
(2)设置当地dnf源

   # mkdir /dvd
# mount /dev/cdrom /dvd
# ls /dvd
# dnf config-manager --add file:///dvd/AppStream
# dnf config-manager --add file:///dvd/BaseOS
# vim /etc/yum.conf
gpgcheck=0
# dnf clean all
# dnf repolist
(3)设置主机名 node1.example.com

   # hostnamectl set-hostname node1.example.com
# bash
(4)关闭防火墙

   # systemctl stop firewalld.service
# systemctl status firewalld.service
(5)SELinux设置强制模式

   # setenforce 1
# getenforce
物理机预备工作

为物理机设置域名解析:修改hosts文件
打开
   C:WindowsSystem32driversetchosts
https://i-blog.csdnimg.cn/direct/f8abe1e8f8ef4dccb0346b32a939ccb4.png
添加在最后一行
   域名:172.25.0.11 server0.example.com www0.example.com webapp0.example.com
https://i-blog.csdnimg.cn/direct/004706703d404ee181503f15f4a2ef3a.png
假造机操作

(1)安装软件包

   # dnf -y install httpd
(2)编写首页文件

   # vim /var/www/html/index.html
   
hxm


以下对应:
滚动 字体颜色 字体巨细 内容
(3)启动服务并且设置开机自启(每次修改完设置文件都需重新启动)

   # systemctl enable --now httpd
https://i-blog.csdnimg.cn/direct/b09add6ed3d24f549be54099e8b0f225.png
增补:

(1)修改设置文件内容说明

   # vim /etc/httpd/conf/httpd.conf
此中设置文件中:
   1.DocumentRoot:为网页文件根目次默认(:/var/www/html)
2.Directory Index:为网页访问的文本默认(index.html)
3.ServerName:为网页路径(在预览器中输入网页路径或IP)
4.结合1,2服务器访问的路径:/var/www/html/index.html
例子:
https://i-blog.csdnimg.cn/direct/0996903b8fed4cbc8161f5127bd31653.png
创建文件部署web站点

为制止需改主设置文件/etc/httpd/conf/httpd.conf出错,根据主设置文件提示可在/etc/httpd/conf.d的目次中创建文件来部署基于域名的假造web站点(假造web主机:同一台服务器上运行多个web站点,此中每一个站点实际上并不独立占据整个服务器的资源,充实利用服务器的资源)
https://i-blog.csdnimg.cn/direct/8ca3b72ceaae408289cfe76a9955666c.png
例子:
创建文件
https://i-blog.csdnimg.cn/direct/e47dc2e021374d72a3c10328caf9a589.png
部署:端口、域名、网页文件根目次、结束符
https://i-blog.csdnimg.cn/direct/a5d2be2510cc41f5bfdcf0998039739a.png
创建目次
https://i-blog.csdnimg.cn/direct/49ee2d6cc7e3400a9f15cd9730fd48c7.png
创建文件并编写
https://i-blog.csdnimg.cn/direct/fd4a64ca94c14aa182ff9f193f2766fa.png
https://i-blog.csdnimg.cn/direct/1ea2dd625706490f94129f2c4708d988.png
重启httpd(修改完每次都重启)
   systemctl restart httpd
https://i-blog.csdnimg.cn/direct/ff9474b394904f999ddaa769d2a301df.png
留意:在物理机host文件添加上该域名(linyin.hhh.com)才能访问到该网页(参考上面物理机预备工作)
网问权限控制页文件访

   <Directory 网页文件根目次的路径>
Require all denied (答应)或granted (拒绝)
Require ip 答应的P地址或网段

例子:
训练:构建web假造站点
###提示:考虑安全上下文(chcon)
编写一个新的web03.conf设置文件,域名:webapp0.example.com
网页文件根目次:/webdir
index.html 的内容:学员姓名拼英缩写
   # vim /etc/httpd/conf.d/web03.conf
<VirtualHost *:80>
ServerName webapp0.example.com
DocumentRoot /webdir
<Directory “/webdir”> ###/webdir1的访问权限放行
Require all granted
    # mkdir /webdir
# echo hxm > /webdir/index.html
# ls -lZd /webdir/ ###上下文标签不答应访问httpd服务
drwxr-xr-x. 2 root root unconfined_u:object_r:default_t:s0 24 Apr 14 22:49 /webdir/
# ls -ldZ /var/www/html
drwxr-xr-x. 2 root root system_u:object_r:**httpd_sys_content_**t:s0 24 Apr 14 19:23 /var/www/html
# chcon -R --reference=/var/www/html /webdir ###修改标签
# ls -lZd /webdir/
drwxr-xr-x. 2 root root system_u:object_r:httpd_sys_content_t:s0 24 Apr 14 22:49 /webdir/
# systemctl restart httpd.service
验证:http://webapp0.example.com
https://i-blog.csdnimg.cn/direct/927a76649a294e108acf220efdab11d2.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: linux搭建网页web假造主机