Linux/centos上如何配置管理Web服务器?

Linux/centos上如何配置管理Web服务器?

  • 1 Web简单了解
  • 2 关于Apache
  • 3 如何安装Apache服务器?
    • 3.1 Apache服务安装
    • 3.2 httpd服务的基本操作
  • 4 如何配置Apache服务器?
    • 4.1 关于httpd.conf配置
    • 4.2 常用指令
  • 5 简单实例

1 Web简单了解

  • Web服务器称为WWW服务器,主要是提供上网功能;
  • 常见的Web服务器有:Microsoft IISIBM WebSphereApacheTomcat等;
  • 本文主要以Apache服务器为例了解一些Linux/centos上如何配置管理Web服务器。

2 关于Apache

  • Apache是一种开源的Web服务器软件;
  • 具有跨平台特性,支持UnixLinuxBSD等操作系统;
  • 支持静态和动态内容;
  • 对于模块化支持;
  • 支持SSL和虚拟主机;
  • 具有完整的日志功能;
  • 支持用户认证机制等。

3 如何安装Apache服务器?

3.1 Apache服务安装

  • 先检查系统上是否已经安装了Apache服务,如下:
rpm -qa | grep httpd
  • 我的是已经安装了如下:
    在这里插入图片描述
  • 如果没有安装,可以使用以下命令安装:
yum -y install httpd

3.2 httpd服务的基本操作

  • 查看httpd服务的运行状态:
systemctl status httpd.service
  • 如下显示,我的还没有启动:
    在这里插入图片描述
  • 启动httpd服务:
systemctl start httpd.service
  • 启动后如下显示:
[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: active (running) since Wed 2023-11-08 17:53:21 CST; 2s agoDocs: man:httpd(8)man:apachectl(8)Main PID: 5953 (httpd)Status: "Processing requests..."Tasks: 9CGroup: /system.slice/httpd.service├─5953 /usr/sbin/httpd -DFOREGROUND├─5954 /usr/libexec/nss_pcache 6 off├─5956 /usr/sbin/httpd -DFOREGROUND├─5958 /usr/sbin/httpd -DFOREGROUND├─5959 /usr/sbin/httpd -DFOREGROUND├─5960 /usr/sbin/httpd -DFOREGROUND├─5961 /usr/sbin/httpd -DFOREGROUND└─5962 /usr/sbin/httpd -DFOREGROUNDNov 08 17:53:20 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Nov 08 17:53:20 localhost.localdomain httpd[5953]: AH00558: httpd: Could not reliably determine the server's fully qualified domain na...message
Nov 08 17:53:21 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
  • 停止httpd服务:
systemctl stop httpd.service
  • 重启httpd服务:
systemctl restart httpd.service
  • 设置开机自启动:
systemctl enable httpd.service
  • 查看设置自启动是否成功:
systemctl list-unit-files | grep httpd
  • 如下显示则为设置成功了:
    在这里插入图片描述

4 如何配置Apache服务器?

4.1 关于httpd.conf配置

  • Apache服务的配置文件为httpd.conf,文件在`/etc/httpd/conf/下:
    在这里插入图片描述
  • httpd.conf文件内容说明:
内容说明
#ServerRoot全局环境设置
#Main serve rconfiguration主服务器设置
虚拟主机设置

4.2 常用指令

指令说明示例
ServerName设置Apache服务器的主机名和端口号ServerName www.noamanelson.com 80
ServerRoot设置Apache服务器的根目录,包括conf、logs、modules等子目录ServerRoot /etc/httpd
Listen设置Apache服务器的监听端口,默认监听80,一般在监听非80时会设置Listen 8088
DocumentRoot设置Apache提供的HTML文档根目录 ,默认为/var/www/htmlDocumentRoot /www/myweb
Directory指定Apache服务器根目录的访问权限和方式<Directory "/var/www">AllowOverride None Require all granted </Directory >
DirectoryIndex设置Apache服务器网站的主文件,通常为index.htmlDirectoryIndex index.html
VirtualHost设置特定虚拟主机<VirtualHost 192.168.1.7> DocumentRoot /www/myweb ServerName noamanelson.com </VirtualHost>
ServerAdmin设置管理员邮箱ServerAdmin admin@noamanelson.com
TimeOut设置接收和发送数据时的超时时间TimeOut 100
ErrorLog指定Apache服务器使用的错误日志文件ErrorLog logs/error_log
CustomLog指定Apache服务器使用的访问日志/
Include其他配置文件/

5 简单实例

  • 主要目标是配置个人Web站点;
  • 建用户NoamaNelson,修改权限,并建立目录public_html:
    在这里插入图片描述
useradd NoamaNelson
mkdir /home/NoamaNelson/public_html
chmod +711 /home/NoamaNelson/
chmod +755 /home/NoamaNelson/public_html/
  • public_html下建立网页文件index,html:
vim /home/NoamaNelson/public_html/index.html
Welcome everyone,
This is my Web~~~
  • 配置/etc/httpd/conf.d/userdir.conf文件:
<IfModule mod_userdir.c>#UserDir disabledUserDir public_html
</IfModule><Directory "/home/*/public_html">AllowOverride FileInfo AuthConfig Limit Indexes#Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExecOptions NoneRequire method GET POST OPTIONS
</Directory>Require method GET POST OPTIONS
  • 保存以上文件,重启服务器,关闭防火墙,将Selinux设置为Permissive
    在这里插入图片描述
systemctl start httpd
systemctl stop firewalld.service
setenforce 0
getenforce
  • 在浏览器中输入服务ip/ ~NoamaNelson/即可打开NoamaNelson的个人主页,比如我的是如下:
    在这里插入图片描述
http://172.28.18.146/~NoamaNelson/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/165284.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

采集Prestashop独立站

这是一个用Lua编写的爬虫程序&#xff0c;用于采集Prestashop独立站的内容。爬虫程序使用代理信息&#xff1a;proxy_host: jshk.com.cn。 -- 首先&#xff0c;我们需要导入所需的库 local http require(socket.http) local url require(socket.url)-- 然后&#xff0c;我们…

Leetcode—2578.最小和分割【简单】

2023每日刷题&#xff08;二十三&#xff09; Leetcode—2578.最小和分割 实现代码 class Solution { public:int splitNum(int num) {vector<int> a;while(num) {a.push_back(num % 10);num / 10;}int n a.size();sort(a.begin(), a.begin() n);int num1 0;int num…

el-select多选以tag展示时,超过显示长度以...省略号显示,且在一行展示

效果&#xff1a; 代码&#xff1a; <span>系统词典维度&#xff1a;</span><el-selectv-model"dNum"placeholder"请选择"multiplecollapse-tags //设置collapse-tags属性将它们合并为一段文字size"small"style"width:160p…

Netty入门指南之NIO Buffer详解

作者简介&#xff1a;☕️大家好&#xff0c;我是Aomsir&#xff0c;一个爱折腾的开发者&#xff01; 个人主页&#xff1a;Aomsir_Spring5应用专栏,Netty应用专栏,RPC应用专栏-CSDN博客 当前专栏&#xff1a;Netty应用专栏_Aomsir的博客-CSDN博客 文章目录 参考文献前言ByteBu…

MySQL库的库操作指南

1.创建数据库 一般格式&#xff1a;create database (if not exists) database1_name,database2_name...... 特殊形式&#xff1a; create database charset harset_name collate collate_name 解释&#xff1a; 红色字是用户自己设置的名称charset&#xff1a;指定数据…

Jupyter Notebook 内核似乎挂掉了,它很快将自动重启

报错原因&#xff1a; OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade perfo…

STM32两轮平衡小车原理详解(开源)

一、引言 关于STM32两轮平衡车的设计&#xff0c;我想在读者阅读本文之前应该已经有所了解&#xff0c;所以本文的重点是代码的分享和分析。至于具体的原理&#xff0c;我觉得读者不必阅读长篇大论的文章&#xff0c;只需按照本文分享的代码自己亲手制作一辆平衡车&#xff0c…

OSPF下的MGRE实验

一、实验要求 1、R1-R3-R4构建全连的MGRE环境 2、R1-R5-R6建立hub-spoke的MGRE环境&#xff0c;其中R1为中心 3、R1-R3...R6均存在环回网段模拟用户私网&#xff0c;使用OSPF使全网可达 4、其中R2为ISP路由器&#xff0c;仅配置IP地址 二、实验拓扑图 三、实验配置 1、给各路…

OAuth2.0双令牌

OAuth 2.0是一种基于令牌的身份验证和授权协议&#xff0c;它允许用户授权第三方应用程序访问他们的资源&#xff0c;而不必共享他们的凭据。 在OAuth 2.0中&#xff0c;通常会使用两种类型的令牌&#xff1a;访问令牌和刷新令牌。访问令牌是用于访问资源的令牌&#xff0c;可…

SpringBoot定时任务打成jar 引入到新的项目中后并自动执行

一、springBoot开发定时任务 ①&#xff1a;连接数据库实现新增功能 1. 引入依赖 <dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional> </dependency> <dependen…

c语言贪吃蛇项目的实现

ncurse的引入 ncurse的概念 ncurse(new curses)是一套编程库&#xff0c;它提供了一系列的函数&#xff0c;以便使用者调用它们去生成基于文本的用户界面。 ncurses是一个能提供功能键定义(快捷键),屏幕绘制以及基于文本终端的图形互动功能的动态库。ncurses用得最多的地方是…

计网----累积应答,TCP的流量控制--滑动窗口,粘包问题,心跳机制,Nagle算法,拥塞控制,TCP协议总结,UDP和TCP对比,中介者模式

计网----累积应答&#xff0c;TCP的流量控制–滑动窗口&#xff0c;粘包问题&#xff0c;心跳机制&#xff0c;Nagle算法&#xff0c;拥塞控制&#xff0c;TCP协议总结&#xff0c;UDP和TCP对比&#xff0c;中介者模式 一.累积应答 1.什么是累计应答 每次发一些包&#xff0…