3_3.Apache的管理及优化web

 ### 一.Apache的作用 ### 

在web被访问时通常使用http://的方式
http:// ##超文本传输协议
http:// 超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

### 二.Apache的安装 ### 

dnf install httpd.x86_64 -y

 ### 三.Apache的启用 ###

systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效

 

### 四.Apache的基本信息 ### 

服务名称:httpd
配置文件: /etc/httpd/conf/httpd.conf   ##主配置文件
                   /etc/httpd/conf.d/*.conf      ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口:  80      #http
                    443    #https
用户:    apache
日志: /etc/httpd/logs 

### 五.Apache的基本配置 ###

(1)Apache端口修改

vim /etc/httpd/conf/httpd.conf
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload 
systemctl restart httpd
http://172.25.254.100:8080

 ​​​​​​

(2)默认发布文件 

vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html
systemctl restart httpd

 (3)默认发布目录

mkdir /var/www/westos
mv /var/www/westos /var
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/var/westos"
<Directory "/var/westos">Require all granted
</Directory>
systemctl restart httpd 
firefox http://192.168.0.11

 ​​​​​

### 六.Apache的访问控制 ### 

#实验素材#
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
<h1>westosdir's page</h1>
firefox http://192.168.0.11/westos

 (1)基于客户端ip的访问控制

#ip白名单# <Directory "/var/www/html/westos">Order Deny,AllowAllow from 192.168.0.10Deny from All
</Directory>#ip黑名单# <Directory "/var/www/html/westos">Order Allow,DenyAllow from AllDeny from 192.168.0.10
</Directory>

(2)基于用户认证 

vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">AuthUserfile /etc/httpd/htpasswdfile ##指定认证文件AuthName "Please input your name and password" ##认证提示语AuthType basic ##认证类型Require user admin ##允许通过的认证用户 2选1
Require valid-user ##允许所有用户通过认证 2选1
</Directory>
htpasswd -cm /etc/httpd/htpasswdfile admin ##生成认证文件注意:当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

###七.Apache的虚拟主机 ### 

mkdir -p /var/www/westos.com/{news,wenku}
echo "wenku's page" >/var/www/westos.com/wenku/index.html
echo "news's page" > /var/www/westos.com/news/index.html
echo "default's page" > /var/www/html/index.html
vim /etc/httpd/Vhost.conf
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog logs/default.log combined
</VirtualHost> <VirtualHost *:80>
ServerName wenku.westos.com
DocumentRoot "/var/www/westos.com/wenku"
CustomLog logs/wenku.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot "/var/www/westos.com/news"
CustomLog logs/news.log combined
</VirtualHost>

测试:
在浏览器所在主机中
vim /etc/hosts
192.168.0.11 www.westos.com wenku.westos.ocm news.westos.comfirefox http://www.westos.com
firefox http://wenku.westos.com
firefox http://news.westos.com

 ### 八.Apache的语言支持 ###

(1)php

vim /var/www/html/index.php
<?php
phpinfo();
?>
dnf install php -y
systemctl restart httpd 
firefox http://192.168.0.11/index.php

 ​​​​​​

(2)cgi 

mkdir /var/www/html/cgidir
vim /var/www/html/cgidir/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
vim /etc/httpd/conf.d/vhost.conf
<Directory "/var/www/html/cgidir">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
firefox http://192.168.0.11/cgidir/index.cgi

 ​​​

 

 ​​​​​​

 ​​​​​

 

(3)wsgi

书写wsgi的测试文件
vim /var/www/html/wsgi/index.wsgidef application(env, westos):westos('200 ok',[('Content-Type', 'text/html')])return [b'hello westos ahhahahahah!']dnf install python3-mod_wsgi
systemctl restart httpd 
vim /etc/httpd/conf.d/vhost
<VirtualHost *:80>ServerName wsgi.westos.orgWSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>

 

​​​​​​​

 

### 九.Apache的加密访问 ###

(1)安装加密插件 

dnf install mod_ssl -y

 (2)生成证书

方法一
openssl genrsa -out /etc/pki/tls/private/www.westos.com.key 2048 #生成私钥
openssl req -new -key /etc/pki/tls/private/www.westos.com.key \ -out /etc/pki/tls/certs/www.westos.com.csr ##生成证书签名文件
openssl x509 -req -days 365 -in \ /etc/pki/tls/certs/www.westos.com.csr \ -signkey /etc/pki/tls/private/www.westos.com.key \ -out /etc/pki/tls/certs/www.westos.com.crt #生成证书

x509 证书格式
-req 请求
-in 加载签证名称
-signkey /etc/pki/tls/private/www.westos.com.key

方法二
openssl req --newkey rsa:2048 \ -nodes -sha256 -keyout /etc/httpd/westos.org.key \ -x509 -days 365 -out /etc/httpd/westos.org.crt

 ​​​​​​​

 (3)强制加密

对于一些需要填登陆信息的网页,无论用户是否进入加密传输,都强制转到加密传输网页

vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1
</VirtualHost> <VirtualHost *:443>
ServerName login.westos.com
DocumentRoot "/www/westos.com/login"
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
systemctl restart httpd
^(/.*)$ ##客户地址栏中输入的地址
%{HTTP_HOST} ##客户主机
$1 ##RewriteRule后面跟的第一串字符的值

 

 ​​​​​

 ​​​​​​​

 ​​​​​​​

 ### 十.Squid+Apache ###

(1)squid 正向代理

实验环境:
单网卡主机设定ip不能上网
双网卡主机设定ip1可以连接单网卡主机,设定ip2可以上网
实验效果
让单网卡主机不能上网但浏览器可以访问互联网页 

操作:
在双网卡主机中
dnf install squid -y
vim /etc/squid/squid.conf
59 http_access allow all
65 cache_dir ufs /var/spool/squid 100 16 256
systemctl restart squid 
firewall-cmd --permanent --add-port=3128/tcp
firewall-cmd --reload
在单网卡专辑中选择
NetWork Proxy
172.25.254.30 3128
测试:
在单网卡主机中
ping www.baidu.com 不通
在浏览器中访问www.baidu.com可以

(2)squid反向代理

实验环境:
172.25.254.100 ##Apache服务器
172.25.254.200 ##squid,没有数据负责缓存

vim /etc/squid/squid.conf
http_port 80 vhost vport ##vhost 支持虚拟域名 vport 支持虚拟端口#当200的80端口被访问会从100的80端口缓存数据
cache_peer 172.25.254.20 parent 80 0 proxy-only
systemctl restart squid 
firewall-cmd --permanent --add-port=3128/tcp
firewall-cmd --reload测试:
firefox http:/172.25.254.200
访问看到的时172.25.254.100上的数据

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

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

相关文章

一、Nginx部署

Nginx部署 一、Docker部署1.复制Nginx配置文件2.启动Nginx容器 一、Docker部署 1.复制Nginx配置文件 # 1.拉取镜像 docker pull nginx # 2.启动nginx容器 docker run --restartalways --namenginx -p 80:80 -d nginx # 3.宿主机创建挂载目录 mkdir /root/docker/nginx -p # 4…

C语言 03 VSCode开发

安装好 C 语言的开发环境后&#xff0c;就需要创建项目进行开发了。 使用 IDE&#xff08;集成开发环境&#xff09;进行开发了。 C 语言的开发工具很多&#xff0c;现在主流的有 Clion、Visual Studio、VSCode。 这里以 VSCode 作为演示。 创建项目 安装 VSCode。 推荐直接在…

【C语言】<动态内存管理>我的C语言终末章

&#xff1c;动态内存管理&#xff1e; 1. 为什么要有动态内存分配2. malloc和free2.1 malloc2.2 free 3. calloc和realloc3.1 calloc3.2 realloc 4.常见的动态内存错误4.1 对NULL指针的解引用操作4.2 对动态开辟空间的越界访问4.3 对非动态开辟内存使用free释放4.4 使用free释…

链表超详解

链表 链表 链表 用途&#xff1a;解决前驱后继类的问题 复杂度&#xff1a;插入删除 O ( 1 ) O(1) O(1) 查找 O ( N ) O(N) O(N)。 例子&#xff1a; 插入&#xff1a;A后面是B,B后面是C编码实现&#xff1a; map<char,char> next; next[A]B;next[B]C;删除B,则A后…

Navicat的安装与破解

个人介绍 hello hello~ &#xff0c;这里是 code袁~&#x1f496;&#x1f496; &#xff0c;欢迎大家点赞&#x1f973;&#x1f973;关注&#x1f4a5;&#x1f4a5;收藏&#x1f339;&#x1f339;&#x1f339; &#x1f981;作者简介&#xff1a;一名喜欢分享和记录学习的…

openEuler-22.03 软件包安装

1、更换软件源 /etc/yum.repos.d/openEuler.repo 默认的一般不需要换 [rootlocalhost ~]# cat /etc/yum.repos.d/openEuler.repo #generic-repos is licensed under the Mulan PSL v2. #You can use this software according to the terms and conditions of the Mulan PSL…

linux下常见解压命令gz、tar、zip详解

常见解压缩命令汇总 # .tar.gz解压 tar -zxvf jdk-17_linux-aarch64_bin.tar.gz # .tar.gz压缩 tar -czvf archive.tar.gz /path/to/directory# .gz解压 gzip -d file.gz # .gz压缩 gzip filename# zip解压 unzip filename.zip # zip压缩 zip archive.zip /path/to/file.tar.g…

累积分布函数图(CDF)的介绍、matlab的CDF图绘制方法(附源代码)

在对比如下两个误差的时候&#xff0c;怎么直观地分辨出来谁的误差更低一点&#xff1f;&#xff1a; 通过这种误差时序图往往不容易看出来。 但是如果使用CDF图像&#xff0c;以误差绝对值作为横轴&#xff0c;以横轴所示误差对应的累积概率为纵轴&#xff0c;绘制曲线图&am…

【经典算法】LeetCode 215. 数组中的第K个最大元素(Java/C/Python3实现含注释说明,Medium)

个人主页&#xff1a; 进朱者赤 阿里非典型程序员一枚 &#xff0c;记录平平无奇程序员在大厂的打怪升级之路。 一起学习Java、大数据、数据结构算法&#xff08;公众号同名&#xff09; 目录 题目描述思路及实现方式一&#xff1a;快速选择排序思路代码实现Java版本C语言版本P…

SpringBoot启动时banner设置

SpringBoot启动时banner设置 1.操作步骤2.各种banner图像 1.操作步骤 在application.properties文件中设置新的banner对于的文件位置&#xff0c;最好放在resources目录下 spring.banner.locationbanner.txt2.各种banner图像 &#xff08;1&#xff09;经典大佛图 具体txt文…

【Linux C | 多线程编程】线程同步 | 互斥量(互斥锁)介绍和使用

&#x1f601;博客主页&#x1f601;&#xff1a;&#x1f680;https://blog.csdn.net/wkd_007&#x1f680; &#x1f911;博客内容&#x1f911;&#xff1a;&#x1f36d;嵌入式开发、Linux、C语言、C、数据结构、音视频&#x1f36d; ⏰发布时间⏰&#xff1a; 本文未经允许…

洛谷P1364医院设置

洛谷P1364 医院设置 医院设置 题目描述 设有一棵二叉树&#xff0c;如图&#xff1a; 其中&#xff0c;圈中的数字表示结点中居民的人口。圈边上数字表示结点编号&#xff0c;现在要求在某个结点上建立一个医院&#xff0c;使所有居民所走的路程之和为最小&#xff0c;同时约…

vue--双向数据绑定原理

Vue采用数据劫持 发布者-订阅者模式实现双向数据绑定&#xff0c;实现逻辑图如下所示&#xff1a; 数据劫持 Vue 借助Object.defineProperty()来劫持各个属性&#xff0c;这样一来属性存取过程都会被监听到 发布者-订阅者模式 主要实现三个对象&#xff1a;Observer&#…

Android 系统编译 and 应用裁剪

平台应用编译 平台应用demo的Android.mk写法: LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS)LOCAL_MODULE_TAGS := optional# Only compile source java files in this apk. LOCAL_SRC_FILES := $(call all-java-files-under, src)LOCAL_PACKAGE_NAME := TestLOCAL_CER…

包装类初识泛型

一.包装类 在Java中, 基本类型不继承于Object类. 所以为了在泛型代码中可以支持基本类型,Java给每个基本类型都对应了一个包装类型.(包装类型相当于引用类型) 1.基本类型对应的包装类 byte -- Byteshort -- Shortint -- Integerlong -- Longfloat -- Floatdouble -- Doublech…

用c++实现串匹配问题、选择排序

5.2.2 串匹配问题 【问题】 给定两个字符串S和T&#xff0c;在主串S中查找子串T的过程称为串匹配(string matching,也称模式匹配&#xff09;&#xff0c;T称为模式。在文本处理系统、操作系统、编译系统、数据库系统以及 Internet 信息检索系统中&#xff0c;串匹配是使用最频…

便宜的dv ssl证书推荐

SSL数字证书是维护互联网安全的重要手段之一。SSL数字证书主要目的是保护客户端和服务器数据传输的安全&#xff0c;防止网站数据在传输过程中被窃取或者篡改。其次&#xff0c;SSL数字证书能够验证网站的身份和合法性&#xff0c;防止用户访问到假冒或钓鱼网站。此外&#xff…

引用拷贝、浅拷贝、深拷贝

在Java中&#xff0c;引用拷贝、浅拷贝和深拷贝的概念可以通过以下代码案例来说明&#xff1a; 引用拷贝&#xff08;直接赋值&#xff09; 案例&#xff1a; public class Main {public static void main(String[] args) {// 创建一个Person对象Person original new Perso…

C语言基础---指针的基本语法

概述 内存地址 在计算机内存中&#xff0c;每个存储单元都有一个唯一的地址(内存编号)。通俗理解&#xff0c;内存就是房间&#xff0c;地址就是门牌号 指针和指针变量 指针&#xff08;Pointer&#xff09;是一种特殊的变量类型&#xff0c;它用于存储内存地址。指针的实…

tomcat热部署热加载原理剖析

Tomcat作为一个流行的Java Web服务器&#xff0c;提供了热部署和热加载的功能&#xff0c;使开发人员能够在不重启服务器的情况下更新应用程序。在本文中&#xff0c;我们将深入探讨Tomcat热部署热加载的原理。 首先&#xff0c;让我们了解一下热部署和热加载的概念。热部署是…