Linux学习篇第三章之~apache
来源:互联网 发布:梦龙网络计划软件使用 编辑:程序博客网 时间:2024/06/07 10:05
Apache基本配置
虚拟主机配置
HTTPS配置
集成动态内容
-------------------------apache信息----------------------------------
1.apache的默认发布信息index.html
2.apache的配置文件
/etc/httpd/conf/httpd.conf
3.apache的默认发布目录
/var/www/html
4.apache的默认端口
80
-------------------------apache的基本配置-------------------------------
1.修改默认发布文件vim /etc/httpd/conf/httpd.conf
2.修改默认发布目录
##当selinux是disable状态
> mkdir /westos/www/test -p> vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
> 浏览器访问172.25.254.243
DocumentRoot "/var/www/html"
DocumentRoot "/westos/www/test" ##允许所有人访问admin目录,但是拒绝243访问
> 155访问成功
> 243访问失败
Directory "/var/www/html/admin"> ##只允许143主机访问admin目录
Order Deny,AllowAllow from 172.25.254.143
Deny from ALL
</Directory>
--------------------------设定用户的访问---------------------------
1.cd /etc/httpd
2.htpasswd -cm /etc/httpd/accessuser admin
New password:
Re-type new password:
Adding password for user admin
3.mkdir /var/www/html/admin
4.vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/accessuser ##用户认证文件
AuthName "Please input your name and password !" ##用户认证提示信息
AuthType basic ##认证类型
Require valid-user ##认证用户,认证文件中所有用户都可以访问
[Require user admin] ##只允许认证文件中admin用户访问,二写一
</Directory>
> 访问
----------------------------apache的虚拟主机-----------------------------------------------
1.定义
可以让我们的一台apache服务器在被访问不同域名的时候显示不同的主页
2.建立测试页
[root@mariadb www]# mkdir virtual/monmy.westos.com/html -p
[root@mariadb www]# mkdir virtual/news.westos.com/html -p
[root@mariadb www]# echo "news.westos.com's page" > virtual/news.westos.com/html/index.html
3.配置vim /etc/httpd/conf.d/default.conf ##未指定域名的访问都访问default
<Virtualhost _default_:80> ##虚拟主机开启的端口
DocumentRoot "/var/www/html" ##虚拟主机的默认发布目录
CustomLog "logs/default.log" combined ##虚拟主机日志
</Virtualhost>
vim /etc/httpd/conf.d/news.conf ##制定域名news.westos.com 的访问到指定默认发布目录
<Virtualhost *:80>
ServerName "news.westos.com"
DocumentRoot "/var/www/virtual/news.westos.com/html"
CustomLog "logs/news.log" combined
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html"> ##默认发布目录的访问授权
Require all granted
</Directory>
4.测试
在浏览器所在的主机中
vim /etc/hosts
> 访问news.westos.com
-----------------------------------https---------------------------
1.https定义
2.配置
yum install crypto-utils -y
yum install mod_ssl -y
genkey www.westos.com ###生成密钥
*生成证书的位置
*选择密钥的位数
*生成随机数
*服务器身份信息
<Virtualhost *:443>
ServerName "login.westos.com"
DocumentRoot "/var/www/virtual/login.westos.com/html"
CUstomLog "logs/login.log" combined
SSLEngine on ##开启https功能
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密钥
</Virtualhost>
<Directory "/var/www/virtual/login.westos.com/html">
Require all granted
</Directory>
<Virtualhost *:80> ##网页重写实现自动访问https
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
----------------------------------------------------------------
^(/.*)$ 客户主机在地址栏中写入的所有字符,不看换行符
https:// 定向成为的访问协议
%{HTTP_HOST} 客户请求主机
$1 表示^(/.*)$的值
[redirect=301] 临时重定向 (302永久重定向)
----------------------------------------------------------------
mkdir /var/www/virtual/login.westos.com/html -p
vim /var/www/virtual/login.westos.com/html/index.html
>login
systemctl restart httpd
3.测试
[root@foundation43 Desktop]# vim /etc/hosts
172.25.254.143 www.westos.com news.westos.com login.westos.com
4.访问
login.westos.com >> https://login.westos.com/
阅读全文
0 0
- Linux学习篇第三章之~apache
- Linux学习篇第三章之~mariadb
- Linux学习篇第三章之~squid
- Linux学习篇第三章之~防火墙
- Linux学习篇第三章之~samba
- Linux学习篇第三章之~nfs
- Linux学习篇第三章之~iscsi
- Linux学习之第三章
- linux学习第三十六篇:MariaDB安装,Apache安装
- linux学习之apache
- Linux学习篇第三章之~高速缓存DNS
- Linux学习篇第三章之~高级网络配置
- Linux学习篇第三章之~postfix & mariadb
- Linux学习篇第三章之~dovecot & mysql + 空壳邮件
- linux学习第三十八篇: Apache和PHP结合,Apache默认虚拟主机
- linux学习第三十九篇:Apache用户认证,域名跳转,Apache访问日志
- 学习linux服务之apache
- Linux学习第三篇
- java中静态变量hashmap赋值给非静态变量,非静值改变,静态值也改变
- 微服务,微架构[六]之springboot集成mybatis
- python文件操作
- B1020. 月饼 (25’)
- 高吞吐低延迟Java应用的垃圾回收优化
- Linux学习篇第三章之~apache
- STA静态时序分析
- 高光谱遥感图像相关知识梳理大全
- 南阳oj-找球号(一) set的常用用法
- Android5.0Button字体大小写
- 多张表合并
- Unity 事件Event
- Xshell使用教程——问答方式
- Maven实战(一)--Why Maven