IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 网络协议 -> Apache的管理与优化 -> 正文阅读

[网络协议]Apache的管理与优化

目录

Apache的简介以及服务安装与启用

1.Apache的作用

?2.Apache的安装与启用?

Apache服务的基本信息及信息优化

1.Apache的基本信息

2.Apache的基本配置

#1.Apache端口修改#

#2.默认发布文件##

#3.默认发布目录

Apache服务的访问控制

#实验素材#

?#1.基于客户端ip的访问控制#

#ip黑名单#

#ip白名单#

#2.基于用户认证#

Apache虚拟主机设定

Apache对语言的支持

#php#

#cgi#

#wsgi#

Apache的加密访问

squid正向代理

squid反向加速代理


Apache的简介以及服务安装与启用

1.Apache的作用

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

?2.Apache的安装与启用?

dnf install httpd.x86_64 -y##安装
systemctl enable --now httpd

##开启服务并设定服务位开机启动

firewall-cmd --list-all

firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https

firewall-cmd --reload

##查看火墙信息

##在火墙中永久开启http访问
##在火墙中永久开启https访问
##刷新火墙使设定生效

Apache服务的基本信息及信息优化

1.Apache的基本信息

服务名称:httpd
配置文件:

/etc/httpd/conf/httpd.conf????????##主配置文件
/etc/httpd/conf.d/*.conf????????##子配置文件

默认发布目录:/var/www/html
默认发布文件:index.html
默认端口:80

用户:apache
日志:/etc/httpd/logs

2.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 test.html index.html
systemctl restart httpd

#3.默认发布目录

mkdir /www/westos -p
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/www/westos"
<Directory "/www/westos">
Require all granted
</Directory>
systemctl restart httpd
firefox http://172.25.254.100

Apache服务的访问控制

#实验素材#

mkdir /var/www/html/westos
vim /var/www/html/westos/index.html

firefox http://172.25.254.100/westos

?#1.基于客户端ip的访问控制#

#ip黑名单#

<Directory "/var/www/html/westos">
Order Allow,Deny
Allow from All
Deny from 172.25.254.34
</Directory>

#ip白名单#

<Directory "/var/www/html/westos">
Order Deny,Allow
Allow from 172.25.254.34
Deny from All
</Directory>

#2.基于用户认证#

vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos">

<Directory "/var/www/html/westos">

AuthUserFile "/etc/httpd/.htpasswd"
AuthName "Please input your name and password !!"
AuthType basic
Require user lee
#Require valid-user
</Directory>

##指定认证文件
##认证提示语
##认证类型
##允许通过的认证用户 (2选1)
##允许所有用户通过认证(2选1)
htpasswd -cm /etc/httpd/htpasswdfile admin##生成认证文件

注意:当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

Apache虚拟主机设定

mkdir -p /var/www/virtual/westos.org/{linux,luck}
echo? linux.westos.org?> /var/www/virtual/westos.org/linux/index.html
echo luck.westos.org > /var/www/virtual/westos.org/luck/index.html
vim /etc/httpd/conf.d/vhost.conf
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog logs/default.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName linux.westos.org?
DocumentRoot? /var/www/virtual/westos.org/linux
CustomLog logs/linux.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName luck.westos.org?
DocumentRoot /var/www/virtual/westos.org/luck
CustomLog logs/luck.log combined
</VirtualHost>
测试:
在浏览器所在主机中
vim /etc/hosts
172.25.254.100 www.westos.org linux.westos.org luck.westos.org
firefox http://www.westos.org
firefox http://linux.westos.org
firefox http:// luck.westos.org

Apache对语言的支持

#php#

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

#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://172.25.254.100/cgidir/index.cgi

#wsgi#

书写wsgi的测试文件
vim /var/www/html/wsgi/index.wsgi
def 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.org
WSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>

firefox http://wsgi.westos.org

Apache的加密访问

##安装加密插件
dnf install mod_ssl -y

##生成证书

##command?
openssl req --newkey rsa:2048 \
-nodes -sha256 -keyout /etc/httpd/westos.org.key \
-x509 -days 365 -out /etc/httpd/westos.org.crt

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正向代理

实验环境:
单网卡主机设定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

测试:
在单网卡主机中

ping www.baidu.com????????不通

在浏览器中访问www.baidu.com可以

在单网卡专辑中选择
NetWork Proxy?

172.25.254.?200? ? ? 3128

squid反向加速代理

实验环境:
172.25.254.100?##Apache服务器

172.25.254.200?##squid,没有数据负责缓存

vim /etc/squid/squid.conf

http_port 80 vhost vport????????##vhost 支持虚拟域名 vport 支持虚拟端口

#当172.25.254.30的80端口被访问会从172.25.254.100的80端口缓存数据

cache_peer 172.25.254.100?parent 80????????0????????proxy-only

systemctl restart squid

测试:
firefox http:/172.25.254.200
访问看到的时172.25.254.100上的数据

  网络协议 最新文章
使用Easyswoole 搭建简单的Websoket服务
常见的数据通信方式有哪些?
Openssl 1024bit RSA算法---公私钥获取和处
HTTPS协议的密钥交换流程
《小白WEB安全入门》03. 漏洞篇
HttpRunner4.x 安装与使用
2021-07-04
手写RPC学习笔记
K8S高可用版本部署
mySQL计算IP地址范围
上一篇文章      下一篇文章      查看所有文章
加:2021-11-28 11:37:38  更:2021-11-28 11:38:35 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年7日历 -2024/7/6 7:57:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码