http搭建静态网页测试

在rhel8的系统上搭建网站:该网站ip地址主机位为11,设置documentroot为/www/你的名字拼音的缩写,网页内容为:my name is...

添加主机位为11的IP地址

#查看网卡信息
[root@server ~]# ip a

#配置主机位为11的IP地址
[root@server ~]# nmcli connection modify ens224 +ipv4.addresses 192.168.32.11/24 ipv4.gateway 192.168.32.2 ipv4.dns 192.168.32.2 ipv4.method manual autoconnect yes

#启动网卡配置,读取所添加的IP
[root@server ~]# nmcli connection up ens224
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

#查看配置后所添加的IP地址
[root@server ~]# ip a | grep ens224
2: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    inet 192.168.32.123/24 brd 192.168.32.255 scope global noprefixroute ens224
    inet 192.168.32.11/24 brd 192.168.32.255 scope global secondary noprefixroute ens224

创建路径文件

#创建路径文件
root@server ~]# mkdir -pv /www/lzh/
mkdir: created directory '/www'
mkdir: created directory '/www/lzh/'
[root@server ~]# touch /www/lzh/index.html
[root@server ~]# tree /www    #查看文件路径是否创建正确
/www
└── lzh
    └── index.html

#写入文件内容
[root@server ~]# echo "my name is..." > /www/lzh/index.html
[root@server ~]# cat /www/lzh/index.html  #查看文件内容是否写入成功
my name is...

安装和配置http服务

#使用yum源安装http服务
[root@server ~]# yum install httpd -y
Complete!

#查看http的配置文件
[root@server ~]# rpm -ql httpd | grep /etc
/etc/httpd/conf
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-optional.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf.modules.d/README
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/httpd/state
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean

#查看配置文件示例
[root@server conf.d]# cat /usr/share/doc/httpd/httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/var/www/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/var/www/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>

#编写配置文件
[root@server conf.d]# vim ip11.conf
<VirtualHost 192.168.32.11:80>
    DocumentRoot "/www/lzh"   #所要访问网页的路径
    ServerName 192.168.32.11
    ErrorLog "/var/log/httpd/ip11_error_log"
    CustomLog "var/log/httpd/ip11_access_log"common
</VirtualHost>

<Directory /www/lzh>  #允许文件被访问
    AllowOverride none
    Require all granted
</Directory>

关闭SELinux

[root@server conf.d]# getenforce
Enforcing
[root@server conf.d]# setenforce 0
[root@server conf.d]# getenforce
Permissive
[root@server conf.d]#

关闭防火墙

[root@server conf.d]# systemctl stop firewalld
[root@server conf.d]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2022-11-13 15:05:11 CST; 14s ago
     Docs: man:firewalld(1)
  Process: 1099 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCES>
 Main PID: 1099 (code=exited, status=0/SUCCESS)

Nov 12 09:20:25 server systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 12 09:20:30 server systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 12 09:20:32 server firewalld[1099]: WARNING: AllowZoneDrifting is enabled. This is considered an insecur>
Nov 13 15:05:11 server systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 13 15:05:11 server systemd[1]: firewalld.service: Succeeded.
Nov 13 15:05:11 server systemd[1]: Stopped firewalld - dynamic firewall daemon.

重启http服务

#重启http服务
[root@server conf.d]# systemctl restart httpd

#查看http服务启动状态
[root@server conf.d]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-11-13 15:30:53 CST; 1min 11s ago
     Docs: man:httpd.service(8)
 Main PID: 16254 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 11088)
    
#监听80端口看看是否开启http服务
[root@server conf.d]# netstat -lntup | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      16254/httpd
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1880/dnsmasq

测试是否能被访问

#在Linux终端窗口测试
[root@server conf.d]# curl http://192.168.32.11
my name is...

#在Windows浏览器窗口访问测试

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值