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 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Linux中Apache的管理及优化 -> 正文阅读

[开发工具]Linux中Apache的管理及优化

一、Apache的作用

在web被访问时通常使用http://的方式
http://?? ??? ??? ?##超文本传输协议

http://?? ?超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

二、Apache的安装以及启用

dnf install httpd.x86_64? -y??? ##安装httpd

firewall-cmd --permanent --add-service=http? ##将http服务加到防火墙的服务名单中

firewall-cmd --permanent --add-service=https ##将https服务加到防火墙的服务名单中

firewall-cmd --reload?? ##重启防火墙,让刚才的操作生效

systemctl enable --now httpd ##启动httpd服务

vim /var/www/html/index.html ##编辑文件

三、Apache的基本配置
配置文件:/etc/httpd/conf/httpd.conf
端口设置:
Listen:8080

默认发布文件:

vim /var/www/html/westos.html##编辑文件

168行左右
<IfModule dir_module>
DirectoryIndex westos.html index.html

firefox查询:172.25.254.137

默认发布目录:
mkdir /westos_apache
vim /westos_apache/index.html

semanage fcontext -a -t httpd_sys_content_t '/westos_apache(/.*)?'

vim /etc/httpd/conf/httpd.conf :
123行左右
#DocumentRoot "/var/www/html"
DocumentRoot "/westos_apache"
<Directory "/westos_apache">
?????????? Require all granted
</Directory>

firefox查询:172.25.254.137

四、Apache访问控制
1)ip限制:
vim /etc/httpd/conf/httpd.conf :
DocumentRoot "/var/www/html"
#DocumentRoot "/westos_apache"
<Directory "/var/www/html/westos">
?????????? Order Deny,Allow
?????????? Deny from all
?????????? Allow from 172.25.254.137
</Directory>
systemctl restart httpd

2)用户限制:
cd /etc/httpd/
mkdir westos ##建立查看文件
vim /westos/index.html
htpasswd -cm .htpasswd admin ##建立用户(环境)

vim /etc/httpd/conf/httpd.conf:
<Directory "/var/www/html/westos">
?????????? AuthUserFile? (用户建立环境在那就指向那里)
?????????? AuthName "Please input username and password"
?????????? AuthType basic
#?????????? Require user? admin
?????????? Require valid-user

systemctl restart httpd

五、Apache的虚拟主机
建立域名、相关文件
mkdir -p /var/www/vhost/westos.org/{news,music,yifan.org}
echo news.westos.org> /var/www/vhost/westos.org/news/index.html
echo music.westos.org> /var/www/vhost/westos.org/music/index.html
echo yifan.westos.org> /var/www/vhost/westos.org/yifan/index.html
echo yifan.org.westos.org> /var/www/vhost/westos.org/yifan.org/index.html

编辑配置文件(服务器)
<VirtualHost _default_:80>
??????? DocumentRoot /var/www/html
??????? CustomLog logs/default.log combined
</VirtualHost>

<VirtualHost *:80>
??????? ServerName music.westos.org
??????? DocumentRoot /var/www/vhost/westos.org/music
??????? CustomLog logs/music.log combined
</VirtualHost>

<VirtualHost *:80>
??????? ServerName news.westos.org
??????? DocumentRoot /var/www/vhost/westos.org/news
??????? CustomLog logs/news.log combined
</VirtualHost>

<VirtualHost *:80>
??????? ServerName yifan.org.westos.org
??????? DocumentRoot /var/www/vhost/westos.org/'yifan'
??????? CustomLog logs/yifan.org.log combined
</VirtualHost>

手动解析域名(浏览器在哪里就在那里写)
vim /etc/hosts:
172.25.254.137 www.westos.org music.westos.org news.westos.org yifan.org.westos.org

测试:
firefox:www.westos.org | music.westos.org | news.westos.org | yifan.org.westos.org(任意一个)

六、Apache的语言支持
#php#
vim /var/www/html/index.php
<?php
?? ?phpinfo();
?>

dnf install php -y
systemctl restart httpd
firefox http://192.168.0.11/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`;

systemctl restart httpd


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

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

七、Apache的加密访问

mkdir /etc/httpd/tls ##建立目录用来存放锁和钥匙

openssl req --newkey rsa:2048 -nodes -sha256 -keyout /etc/httpd/tls/westos.org.key -x509 -days 365 -out /etc/httpd/tls/westos.org.crt?? ##建立锁和钥匙

vim /etc/httpd/conf.d/vhost.conf

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-08-02 11:00:04  更:2021-08-02 11:00:51 
 
开发: 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年4日历 -2024/4/28 14:17:38-

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