Linux配置HTTP服务

1、 关闭防火墙

[root@centos ~]# systemctl stop firewalld        #临时关闭防火墙
[root@centos ~]# systemctl disable firewalld #永久关闭防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

2、配置yum本地仓库

   2.1挂载光盘

[root@centos yum.repos.d]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 59G 0 part
├─centos-root 253:0 0 37G 0 lvm /
├─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
└─centos-home 253:2 0 18.1G 0 lvm /home
sr0 11:0 1 4.3G 0 rom
[root@centos yum.repos.d]# cd
[root@centos ~]# mkdir /mnt/abc
[root@centos ~]# mount /dev/sr0 /mnt/abc
mount: /dev/sr0 is write-protected, mounting read-only

2.2进入/etc/yum.repods.d文件夹中,并清除文件里面的东西

[root@centos ~]# cd /etc/yum.repos.d/
[root@centos yum.repos.d]#
[root@centos yum.repos.d]#
[root@centos yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@centos yum.repos.d]# rm -rf *

2.3创建yum文本

[root@centos ~]# vim /etc/yum.repos.d/dvd.repo  
[dvd] //ID号,自定义,固定格式
name=dvd //名称,自定义,固定格式
baseurl=file:///mnt/abc //基础路径,file://为固定格式,/mnt/abc为路径
gpgcheck=0 //对rpm包的合法性不进行验证
enabled=1 //确认生效

2.4验证

[root@centos ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: dvd
[root@centos ~]# yum repolist all
Loaded plugins: fastestmirror
Determining fastest mirrors
dvd | 3.6 kB 00:00:00
(1/2): dvd/group_gz | 166 kB 00:00:00
(2/2): dvd/primary_db | 3.1 MB 00:00:00
repo id repo name status
dvd dvd enabled: 4,021
repolist: 4,021

2.5安装httpd服务

[root@centos ~]# yum install -y httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================
Installing:
httpd x86_64 2.4.6-88.el7.centos dvd 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7_4.1 dvd 103 k
apr-util x86_64 1.5.2-6.el7 dvd 92 k
httpd-tools x86_64 2.4.6-88.el7.centos dvd 90 k
mailcap noarch 2.1.41-2.el7 dvd 31 k

Transaction Summary
==============================================================================================================================================
Install 1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Downloading packages:
----------------------------------------------------------------------------------------------------------------------------------------------
Total 148 MB/s | 3.0 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-88.el7.centos.x86_64 5/5
Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 1/5
Verifying : apr-1.4.8-3.el7_4.1.x86_64 2/5
Verifying : mailcap-2.1.41-2.el7.noarch 3/5
Verifying : httpd-2.4.6-88.el7.centos.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7.x86_64 5/5

Installed:
httpd.x86_64 0:2.4.6-88.el7.centos

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@centos ~]#

3、 启动服务,并设置为开机启动

[root@centos ~]# systemctl start httpd
[root@centos ~]# systemctl enable httpd
[root@centos ~]# service httpd status
Redirecting to /bin/systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-11-17 15:04:37 CST; 2min 33s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 10761 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─10761 /usr/sbin/httpd -DFOREGROUND
├─10762 /usr/sbin/httpd -DFOREGROUND
├─10763 /usr/sbin/httpd -DFOREGROUND
├─10764 /usr/sbin/httpd -DFOREGROUND
├─10765 /usr/sbin/httpd -DFOREGROUND
└─10766 /usr/sbin/httpd -DFOREGROUND

Nov 17 15:04:12 centos systemd[1]: Starting The Apache HTTP Server...
Nov 17 15:04:27 centos httpd[10761]: AH00558: httpd: Could not reliably determine ...age
Nov 17 15:04:37 centos systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos ~]#

3.1打开浏览器查看

​http://本机IP​​ #本机ip地址,成功显示

Linux配置HTTP服务

4、配置服务器参数

各个httpd服务目录

服务地址

服务目录

/etc/httpd

配置文件目录

/etc/httpd/conf/httpd.conf

网站数据目录

/var/www/html

访问日志目录

/var/log/httpd/access_log

错误日志目录

/var/log/httpd/error_log

默认的网站数据是存放在/var/www/html目录中的,首页名称为index.html

添加内容“Hello Centos”到index.html

[root@centos ~]# echo "Hello Centos" > /var/www/html/index.html

查看浏览器

Linux配置HTTP服务

5、修改主配置文件httpd.conf,开启网页

5.1建立网站数据目录

[root@centos ~]# mkdir /home/Centos

5.2创建首页文件

[root@centos ~]# echo "Welcome to the homepage of Centos" > /home/Centos/index.html

5.3修改配置文件

DocumentRoot参数修改为“/home/Centos"

Directory中的"/var/www"修改为 "/home/Centos"

[root@centos ~]# vim /etc/httpd/conf/httpd.conf

Linux配置HTTP服务

5.4重启Apache服务

[root@centos ~]# systemctl restart httpd
[root@centos ~]#
#没报错代表重启成功

#注意:如果重启完之后,读不到/home/Centos/index.html里面的内容,则有可能是因为centos的防火墙没关。关闭之后显示Permissive就行了

[root@centos conf]# getenforce 
Enforcing
[root@centos conf]# setenforce 0
[root@centos conf]# getenforce
Permissive
[root@centos conf]#

再次查看浏览器,成功Linux配置HTTP服务

发表评论

相关文章