apache

来源:互联网 发布:软件卡住关不掉 编辑:程序博客网 时间:2024/06/16 20:12

1 apache

企业中常用的web服务,用来提供http://(超文本传输协议)

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

2 apache的安装部署

yum install httpd -y

yum install httpd-manual

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld

测试: http://172.25.254.xxx

http://172.25.254.xxx/manual

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

3 apache的基础信息

主配置目录: /etc/httpd/conf rpm -qc httpd

主配置文件: /etc/httpd/conf/httpd.conf

子配置目录: /etc/httpd/conf.d/

子配置文件: /etc/httpd/conf.d/*.conf

默认发布目录: /var/www/html

默认发布文件: index.html

默认端口: 80 查看端口:ss -anutlpe | grep httpd

这里写图片描述

默认安全上下文: httpd_sys_content_t 查看安全上下文:ls -ldZ /var/www/html/

程序开启默认用户: apache

apache日志: /etc/httpd/logs/* 四种:访问,错误,警告,定制日志

浏览器所在主机的本地解析文件:/etc/hosts

修改默认端口:

vim /etc/httpd/conf/httpd.conf

43 Listen 8080 ##修改默认端口为8080

查看端口:ss -anutlpe | grep httpd

这里写图片描述

修改默认发布目录:

120 DocumentRoot “/www/html”

121

122 Require all granted

123

这里写图片描述

mkdir /www/html/ -p

vim /www/html/index.html

semanage fcontext -a -t httpd_sys_content_t ‘/www(/.*)?’ :修改安全上下文

storecon -RvvF /www/

[root@server ~]# cat /etc/httpd/conf.d/linux.conf

这里写图片描述

ServerName linux.westos.com #指定站点名称

DocumentRoot “/var/www/var/linux.westos.com/html” ##站点默认发布目录

CustomLog “logs/linux.westos.com.logs” combined #站点的四种日志存放地方

Require all granted

这里写图片描述
这里写图片描述

[root@server ~]# cat /etc/httpd/conf.d/adefault.conf

DocumentRoot “/var/www/html”

CustomLog “logs/www.westos.com.log” combined

这里写图片描述
这里写图片描述
这里写图片描述

这里写图片描述
这里写图片描述

本地解析

主机:/etc/hosts

172.25.254.127 c.westos.com www.westos.com linux.westos.com

5 apache内部的访问控制

1.针对与主机的访问控制

5

6 Order deny,allow ##列表读取顺序,后读的列表会覆盖先读取内容的重复部分

7 Allow from 172.25.254.56

8 Deny from all

9

2. 用户方式的访问控制

htpasswd -cm /etc/httpd/userpass admin #重新创建

htpasswd -m /etc/httpd/userpass admin1 #添加

这里写图片描述

vim adefault.conf

AuthUserFile /etc/httpd/userpass

AuthName “Please input your name and passwd”

AuthType basic

#Require user admin #只允许admin访问

Require valid-user #允许全部

这里写图片描述
这里写图片描述
这里写图片描述

6 apache支持的语言

1.html

2.php

yum install php -y

systemctl restart httpd

测试

172.25.254.100/index.php

vim /var/www/html/index.php

phpinfo();

?>

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

3.cgi

mkdir -p /var/www/html/cgi

semanage fcontext -a -t httpd_sys_script_exec_t ‘var/www/html/cgi(/.*)?’ #安全上下文的修改

restorecon -RvvF /var/www/html/cgi/

vim /var/www/html/cgi/index/cgi

!/usr/bin/perl

这里写图片描述

chmod +x /var/www/html/cgi/index.cgi

/var/www/html/cgi/index.cgi #执行下脚本确保脚本运行正常

这里写图片描述

vim /etc/httpd/conf.d/adefault.conf

Options +ExecCGI

AddHandler cgi-script .cgi

systemctl restart httpd

这里写图片描述
这里写图片描述

7 设定https虚拟主机并设定网页的重写

作用:让默认的http自动调转到加密的https文本传输中

https的默认端口是443 所以先需要安装

yum install crypto-utils

yum install mod_ssl -y

这里写图片描述
这里写图片描述

genkey www.westos.com

这里写图片描述
这里写图片描述

vim /etc/httpd/conf.d/ssl.conf

101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt

109 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

这里写图片描述

这个就是证书

这里写图片描述
这里写图片描述

systemctl restart httpd

https://login.westos.com/

ServerName login.westos.com

RewriteEngine on

RewriteRule ^(/.*)https://1 [redirect=301]

^(/.*)$ ##客户在浏览器地址中输入的所有字符

https:// ##强制客户加密访问

%{HTTP_HOST} ##客户请求主机

1         ##"1”标示 ^(/.*)$的值

[redirect=301] ##临时重写 302永久转换

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

THE END!

原创粉丝点击