#####apache
apache
企业中常用的web服务,用来提供http://(超文本协议)
#
=apache安装部署==================================================
yum install httpd -y
yum install httpd-manual
systemctl start httpd.service
systemctl enable httpd.service
systemctl stop firewalld.service
systemctl disable firewalld.service
测试:http://172.25.254.101
http://172.25.254.101/manual
================================================================
=apache的基础信息=================================================
/etc/httpd/conf主配置目录
/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/conf.d 子配置目录
/etc/httpd/conf.d/*.conf 子配置文件
/var/www/html 默认发布目录
index.heml 默认发布文件
80 默认端口
httpd_sys_content_t 默认安全上下文
apache 程序开启默认用户
apache 日志
=====================================================================
修该默认端口:
vim /etc/httpd/conf/httpd.conf
43 Listen 8080 #修改默认端口为8080
=====================================================================
默认发布文件
默认发布文件就时访问apache时没有指定文件名称时默认访问的文件
这个文件可以指定多个,有访问顺序(如果需要指定 则需要加据对路径)
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex index.html #当indeex.html不存在时访问test.html
(apache默认的目录里创建访问内容 内容随便!)
======================================================================
如何修改默认发布目录
120 DocumentRoot "/www/html"
121 <Directory "/www">
122 Require all granted
123 </Directory>
mkdir /www/html/ -p
vim /www/html/index.html
semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'
storecon -RvvF /www/
在主配置文件把默认目录改为“www/html”
由于系统没有我们设置的目录所以要创建出来
然后再在默认目录下创建默认文件(为什么是index.heml因为主配置文件默认是这个)
然后更改文件的安全上上文
!!!记住要重起httpd服务!!!
现在开始测试:
========================================================================
apache的虚拟主机
mkdir /var/www/virtual/linux.westos.com/html/index.html 文件发布目录
vim /etc/httpd/conf.d/adefault.conf
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<VirtualHost _default_:80>
DocumentRoot "/var/www/html"
CustomLog "logs/www.westos.com.log" combined
</VirtualHost> 默认文件发布目录
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@localhost Desktop]# cat /etc/httpd/conf.d/linux.conf
<VirtualHost *:80>
ServerName linux.westos.com 指定文件站点名称
DocumentRoot "/var/www/virtual/linux.westos.com/html" 站点默认发布目录
CustomLog "logs/linux.westos.com.logs" combined 站点日志
</VirtualHost>
<Directory "/var/www/virtual/linux.westos.com/html/">
Require all granted
</Directory>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@localhost Desktop]# cat /etc/httpd/conf.d/c.conf
<VirtualHost *:80>
ServerName c.westos.com
DocumentRoot "/var/www/virtual/c.westos.com/html"
CustomLog "logs/c.westos.com.logs" combined
</VirtualHost>
<Directory "/var/www/virtual/c.westos.com/html/">
Require all granted
</Directory>
测试:
在测试主机中做好本地解析
vim /etc/hosts
172.25.254.101
创建两个文件中所指定的目录
在目录下写需要访问的东西(由于主配置文件默认访问文件是index.html 所以写的东西必须在这个文件里)
然后做好本地解析(注意:你用哪个浏览器访问就在哪里作本地解析)
做完本地解析后来验证刚才写的东西
===================================================================
apache内部的访问控制
针对主机的访问控制
在主,子文件里面加都可以
</Directory “/var/www/html/test>
Order deny,allow ##列表读取顺序,后读的列表会覆盖先读取内容的重复部分
Allow frow 172.25.254.101
Deny from all
</Directory>
++++++++++++++++++++++++++++++++++++
用户方式访问控制
htpasswd -cm /etc/httpd/userpass admin(在这文件下面创建用户)
htpasswd -m /etc/httpd/userpass admin1(再添加一定要去掉C要不然会覆盖所有)
mkdir /var/www/html/admin
vim adefault.conf
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/userpass
AuthName "Please input your name and password"
AuthType basic
#Require user admin(指定admin用户)
Require valid-user(所有用户)
</Directorty
=====================================================================
apache支持的语言
1.html
2.php
vim /var/www/html/index.php
+++++++++++++++++++++++++++++++++++
<?php
phpinfo();
?>
+++++++++++++++++++++++++++++++++++
yum install php -y
测试:
172.25.254.101/index.php
+++++++++++++++++++++++++++++++++++++
mkdir -p /var/www/html/cgi
semanage fcontext -a -t b 'var/www/html/cgi(/.*)?'
restorecon -RvvF /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
chmod +x /var/www/html/cgi/index.cgi
/var/www/html/cgi/index.cgi #执行下脚本确保脚本运行正常
vim /etc/httpd/conf.d/adefault.conf
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
systemctl restart httpd
================================================================
https
yum install crypto-utils -y
yum install mod_ssl.x86_64
genkey www.westos.com
vim /etc/httpd/conf.d/ssl.conf
101 SSLCertificateFile /etc/pki/tls/certs/wwww.westos.com.crt
109 SSLCertificatKeyFile /etc/pki/tls/private/www.westos.com.key
systemctl restart httpd
https://login.westos.com/
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
===================================================================
设定https虚拟主机并设定网页重写
^(/.*)$ 客户在浏览器地址栏中输入的所有字符
https:// 强制客户加密访问
%{HTTP——HOST} 客户请求主机
$1 表示这个^(/.*)$的值
[redirect=301] 临时重写 302永久转换