Linux高级课程------web服务器

本文详细介绍了在RHEL8系统上搭建个人网站的步骤,包括配置IP地址为主机位11,设置DocumentRoot,创建网页内容,安装并配置httpd服务,修改防火墙和SELinux设置,最终实现通过IP地址访问自定义网页。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

www简介:

 

         www是world wide web的缩写,也就是全球信息广播的意思。通常说的上网就是使用www来查询用户所需要的信息。www可以结合文字、图形、影像以及声音等多媒体,并通过可以让鼠标单击超链接的方式将信息以Internet传递到世界各处去。

具体过程如下图:

相关习题:

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

首先:查看IP地址

[root@red-85 ~]# ip a
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:80:d5:dc brd ff:ff:ff:ff:ff:ff
    inet 192.168.240.128/24 brd 192.168.240.255 scope global dynamic noprefixroute ens160
       valid_lft 1126sec preferred_lft 1126sec
    inet6 fe80::20c:29ff:fe80:d5dc/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

配置主机位为11的IP地址

[root@red-85 ~]# nmcli connection modify  ens160 +ipv4.addresses 192.168.240.11/24 ipv4.gateway 192.168.240.2 ipv4.dns 192.168.240.2 ipv4.method  manual autoconnect  yes

重启服务

[root@red-85 ~]# nmcli connection up ens160

查看IP地址

[root@red-85 ~]# ip a
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:80:d5:dc brd ff:ff:ff:ff:ff:ff
    inet 192.168.240.11/24 brd 192.168.240.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe80:d5dc/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

创建文件

[root@red-85 ~]# mkdir -pv /www/tx
mkdir: created directory '/www'
mkdir: created directory '/www/tx'
[root@red-85 ~]# touch /www/tx/index.html

查看创建的文件位置

[root@red-85 ~]# tree /www
/www
└── tx
    └── index.html

1 directory, 1 file

在配置文件中写入内容


[root@red-85 ~]# echo "my name is ..." > /www/tx/index.html
[root@red-85 ~]# cat /www/tx/index.html
my name is ...
[root@red-85 ~]#

安装httpd服务

[root@red-85 ~]# yum install httpd
Complete!

查看文件示例


[root@red-85 ~]# 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@red-85 ~]# vim iptx11.conf
<VirtualHost 192.168.240.11:80>
    DocumentRoot "/www/tx"  #所需要访问的网页
    ServerName 192.168.240.11
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
<\VirtualHost >


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

关闭seliux

[root@red-85 ~]# getenforce
Enforcing
[root@red-85 ~]# setenforce 0
[root@red-85 ~]# getenforce
Permissive
[root@red-85 ~]#

查看防火墙状态并关闭

[root@red-85 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2022-11-27 16:32:03 CST; 53min ago
     Docs: man:firewalld(1)
 Main PID: 997 (firewalld)
    Tasks: 2 (limit: 4652)
   Memory: 860.0K
   CGroup: /system.slice/firewalld.service
           └─997 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid

Nov 27 16:32:00 red-85 systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 27 16:32:03 red-85 systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 27 16:32:04 red-85 firewalld[997]: WARNING: AllowZoneDrifting is enabled. This is considered>

[root@red-85 ~]# systemctl stop firewalld
[root@red-85 ~]# 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-27 17:25:47 CST; 1s ago
     Docs: man:firewalld(1)
  Process: 997 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, stat>
 Main PID: 997 (code=exited, status=0/SUCCESS)

Nov 27 16:32:00 red-85 systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 27 16:32:03 red-85 systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 27 16:32:04 red-85 firewalld[997]: WARNING: AllowZoneDrifting is enabled. This is considered>
Nov 27 17:25:46 red-85 systemd[1]: Stopping firewalld - dynamic firewall daemon...
Nov 27 17:25:47 red-85 systemd[1]: firewalld.service: Succeeded.
Nov 27 17:25:47 red-85 systemd[1]: Stopped firewalld - dynamic firewall daemon.
lines 1-13/13 (END)

重启服务

[root@red-85 ~]# systemctl restart httpd
[root@red-85 ~]# 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-27 17:26:31 CST; 15s ago
     Docs: man:httpd.service(8)
 Main PID: 4282 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 4652)
   Memory: 24.8M
   CGroup: /system.slice/httpd.service
           ├─4282 /usr/sbin/httpd -DFOREGROUND
           ├─4283 /usr/sbin/httpd -DFOREGROUND
           ├─4284 /usr/sbin/httpd -DFOREGROUND
           ├─4285 /usr/sbin/httpd -DFOREGROUND
           └─4286 /usr/sbin/httpd -DFOREGROUND

Nov 27 17:26:30 red-85 systemd[1]: Starting The Apache HTTP Server...
Nov 27 17:26:31 red-85 httpd[4282]: AH00558: httpd: Could not reliably determine the server's fu>
Nov 27 17:26:31 red-85 systemd[1]: Started The Apache HTTP Server.
Nov 27 17:26:31 red-85 httpd[4282]: Server configured, listening on: port 80

验证

[root@red-85 ~]# curl http://192.168.240.11

my name is ...

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值