快盘下载:好资源、好软件、快快下载吧!

快盘排行|快盘最新

当前位置:首页软件教程电脑软件教程 → Linux配置HTTP服务

Linux配置HTTP服务

时间:2022-11-18 16:09:08人气:作者:快盘下载我要评论

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

查看浏览器

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

centos

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]#

再次查看浏览器,成功centos


















相关文章

  • centos7-环境安装-PM2-管理-node

    centos7-环境安装-PM2-管理-node,前言: 由于最新的项目中用到的框架是 ssr 框架。 Vue使用的ssr是 nuxt.js,由于 nuxt.js 和普通的Vue项目不同,所以部署到Linux服务器的方式和普通的Vue项目是有区别的。PM2 是一款非常优秀的 Node 进程管理工具,它有着丰富的特性:能够充分利用多核 CPU且能够负载均衡、能够帮助应用在崩溃后、指定时间(cluster model)和超出最大内存限制等情况下实现自动重启。PM2 是开源的基于 Nodejs 的进程管理器,包...
  • ssh登录linux

    ssh登录linux,上一篇提到用ssh登录centos好处很多,许多linux系统管理员都在用ssh。在windows下ssh客户端主要有puTTY、Xshell、secureCR......

网友评论

快盘下载暂未开通留言功能。

关于我们| 广告联络| 联系我们| 网站帮助| 免责声明| 软件发布

Copyright 2019-2029 【快快下载吧】 版权所有 快快下载吧 | 豫ICP备10006759号公安备案:41010502004165

声明: 快快下载吧上的所有软件和资料来源于互联网,仅供学习和研究使用,请测试后自行销毁,如有侵犯你版权的,请来信指出,本站将立即改正。