网安
  • Develop
    • JAVA学习
      • 字节码
      • API开发
      • Web开发
      • 工程结构推荐
      • 创建第一个项目
      • 权限管控
      • 配置文件
      • 日志管理
      • 数据访问
      • 性能监控
      • IoC容器
      • Spring
      • Filter与Listener
      • jsp
      • MVC
      • servlet-1
      • servlet-2
      • servlet-3
      • servlet-4
      • FreeMarker
      • Thymeleaf
      • EL
      • SpEL
      • JSTL
      • 部署
      • JDBC
      • 数据库连接池
      • fastjson
      • jackson
      • XML
      • JSON
      • 序列化
      • Maven
      • 安装与使用
      • 工具
      • 爬虫
    • GO学习
      • GO
        • flag 包
        • goland 远程调试
        • GoReleaser
        • OS 包
        • time 包
        • 格式化输出
    • Lua学习
      • Lua
      • 基础语法
      • LuaJIT
      • 与系统交互
    • Pyhon
      • 基础
      • Django
      • CLI
      • miniforge
      • MockingBird
      • pdb
      • pyc
      • 装的我脑血栓要犯了
      • Python101
      • 反序列化
      • 爬虫
      • Pillow
      • 图像识别
      • flask
    • Speed-Ruby
      • 入门1
      • 入门2 对象
      • 入门3 创建命令
      • Encoding类
      • File类与Dir类
      • IO
      • Proc类
      • Time类与Date类
      • 正则
      • 错误处理与异常
      • 对象、变量和常量
      • 方法
      • 数值
      • 数组
      • 条件判断
      • 循环
      • 运算符
      • Socket编程
      • 字符串
      • 并发与线程
      • 块
      • 类和模块
      • 散列
    • Web
      • HTTP
        • Connection
        • HTTP 报文
        • Vary
      • 笔记
        • 跳转
        • 认证 & 授权
        • 同源策略(SOP)
        • 文件
    • Git 学习笔记
    • JSON
      • JSON 学习笔记
    • HTML
      • Speed-HTML
      • 语法学习
      • HTML字符实体
    • XML
      • XML 学习笔记
    • 计算机基础
      • 操作系统
      • 计算机组成
      • 算法
      • 内存
      • 字符编码
    • gnuplot 学习笔记
    • regex
  • Integrated
    • Linux
      • God-Linux
      • Secure-Linux
      • Power-Linux
      • IO模型
      • Speed-Linux
      • 发行版
      • 工具
      • 启动过程
      • 进程
      • 认证
      • 日志
      • 守护进程
      • 文件
      • 信息
      • VSFTP 配置案例
      • auditd
      • containerd
      • DNS 配置案例
      • Docker
      • Docker-Compose
      • firewalld 实验
      • gpg
      • Iptables
      • httpd
      • LAMP
      • mysql
      • nfs 配置案例
      • openssl
      • PAM
      • samba 配置案例
      • terraform
      • ufw
      • VSFTP 配置案例
    • Network
      • Speed-Net
      • Power-Net
      • SDN 笔记
      • DNS
      • TLS
    • Windows
      • Secure-Win
      • Speed-Win
      • ACL
      • LDAP
      • IPC$(Internet Process Connection)
      • PDB符号文件
      • 工作组
      • WinRM
      • 角色权限
      • 凭据
      • 签名
      • 日志
      • 认证
      • 协议
      • 信息
      • 应用
      • 组策略
      • 域
      • asp站点搭建
      • Exchange 搭建
      • Windows 故障转移集群
      • Windows 基础服务搭建
      • Windows 域搭建
      • 本地抓包
      • PowerShell 笔记
    • 容器
      • Docker
    • 数据库
      • Speed-SQL
      • Power-SQL
      • MSSQL
      • MySQL
      • Postgresql
      • Redis
      • MySQL大小写问题
      • 主键和外键
      • MySQL快速入门
      • 虚拟化
        • ESXi
        • vCenter
  • Plan
    • Mac-Plan
    • Misc-Plan
    • Team-Plan
    • Thinking-Plan
    • VM-Plan
  • Sercurity
    • Power-PenTest
    • BlueTeam
      • 安全建设
      • 分析
      • 加固
      • 取证
      • 应急
      • USB取证
      • 磁盘取证
      • 内存取证
      • ClamAV 部署
      • yara 实验
      • 安防设施搭建使用
      • ZIP明文攻击
      • 流量分析
    • Crypto
      • Crypto
        • 2020 9 G60攻防大赛
        • CTF
        • 2020 9 中能融合杯工控CTF
        • 2020 10 全国工业互联网安全技术技能大赛江苏省选拔赛
        • 2020 10 全国网络与信息安全管理职业技能大赛江苏场
        • 2020 11 I²S峰会暨工业互联网安全大赛
        • 2021 6 第二届I²S峰会暨工业互联网安全大赛
        • 2021-9-第七届工控信息安全攻防竞赛
        • 2021 9 第七届全国职工职业技能大赛某市县选拔赛
        • 2021 9 全国网络与信息安全管理职业技能大赛江苏场
        • 2021-10-G60攻防大赛
    • CTF
      • CTF
      • writeup
        • 2020 9 中能融合杯工控CTF
        • 2020 9 G60攻防大赛
        • 2020 10 全国工业互联网安全技术技能大赛江苏省选拔赛
        • 2020 10 全国网络与信息安全管理职业技能大赛江苏场
        • 2020 11 I²S峰会暨工业互联网安全大赛
        • 2021 6 第二届I²S峰会暨工业互联网安全大赛
        • 2021-9-第七届工控信息安全攻防竞赛
        • 2021 9 第七届全国职工职业技能大赛某市县选拔赛
        • 2021 9 全国网络与信息安全管理职业技能大赛江苏场
        • 2021-10-G60攻防大赛
    • ICS
      • PLC攻击
      • S7comm 相关
      • 工控协议
      • 上位机安全
      • Modbus 仿真环境搭建
      • siemens 仿真搭建实验
      • S7-300 启停实验
    • IOT
      • 无线电安全
        • RFID复制卡
        • RFID基础知识
        • WiFikiller
      • 硬件安全
        • DIY键盘嵌入指纹识别模块实验记录
        • Device-Exploits
        • HID-Digispark
        • HID-KeyboardLogger
        • HID-USBHarpoon
        • HID-USBKeyLogger
      • 固件安全
        • 固件安全
        • Dlink_DWR-932B 路由器固件分析
    • Mobile sec
      • 小程序安全
      • Android安全
    • PWN
      • SLMail溢出案例
      • PWN
    • Red Team
      • OS安全
        • Linux 安全
        • Exploits
        • NTLM中继
        • Windows 安全
        • Responder欺骗
        • Windows-LOL
      • Web_Generic
        • Top 10
          • RCE
          • Fileread
          • SQLi
          • SSRF
          • SSTI
          • Web Generic
          • XSS
          • XXE
      • Web_Tricks
        • JWT 安全
        • HTTP_request_smuggling
        • OOB
        • 绕过访问
      • 靶场
        • Hello-Java-Sec 学习
        • DVWA-WalkThrough
        • pikachu-WalkThrough
        • upload-labs-WalkThrough
        • XVWA-WalkThrough
        • XSS挑战-WalkThrough
      • 实验
        • flask
        • fastjson
        • Log4j
        • nodejs
        • Shiro
        • Spring
        • Weblogic
      • 前端攻防
      • IDOR
    • 安防设备
      • Exploits
      • Bypass 技巧
    • 后渗透
      • 权限提升
      • 后渗透
      • 权限维持
      • 实验
        • C2 实验
        • Exchange
        • 端口转发实验
        • 代理实验
        • 免杀实验
        • 隧道实验
    • 软件服务安全
      • Exploits
      • CS Exploits
      • 实验
        • Docker
        • Kubernetes
        • Mysql
        • Oracle
        • PostgreSQL
        • Redis
        • vCenter
    • 协议安全
      • Exploits
    • 信息收集
      • 端口安全
      • 空间测绘
      • 信息收集
    • 语言安全
      • 语言安全
        • 语言安全
      • GO安全
        • GO安全
        • Go代码审计
      • JAVA安全
        • JAVA安全
        • JAVA代码审计
        • JAVA反序列化
        • SpEL 注入
      • PHP安全
        • PHP安全
        • bypass_disable_function
        • bypass_open_basedir
        • phpinfo
        • PHP代码审计
        • PHP反序列化
        • PHP回调函数
        • 变量覆盖
        • POP
        • 弱类型
        • 伪协议
        • 无字母数字Webshell
      • Python安全
        • pyc反编译
        • Python安全
        • Python 代码审计
        • 沙箱逃逸
      • dotnet安全
      • JS安全
    • 云安全
      • 公有云安全
    • Reverse
      • Reverse
      • FILE
        • ELF
        • BMP
        • JPG
        • PE
        • PNG
        • ZIP
        • 文件头
      • 实验
        • PYAble
          • 2-逆运算
          • 1-基本分析
          • 3-异或
          • 4-Base64
          • 5-Base64换表
          • 6-动态调试
        • Windows
          • condrv.sys 内存损坏漏洞
    • 工具
      • Aircrack
      • BloodHound
      • Burp Suite
      • frp
      • CobaltStrike
      • Ghidra
      • fscan
      • Hashcat
      • IDA
      • merlin
      • Kali
      • Metasploit
      • Mimikatz
      • ModSecurity
      • Nmap
      • nps
      • nuclei
      • pupy
      • RedGuard
      • SET
      • sliver
      • Snort
      • Sqlmap
      • Suricata
      • Sysmon
      • uncover
      • Volatility
      • Wfuzz
      • Wireshark
      • xray
    • 安全资源
      • 靶机
        • VulnHub
          • DC
            • DC2 WalkThrough
            • DC1 WalkThrough
            • DC3 WalkThrough
            • DC4 WalkThrough
            • DC5 WalkThrough
            • DC6 WalkThrough
            • DC9 WalkThrough
            • DC8 WalkThrough
          • It's_October
            • It’s_October1 WalkThrough
          • Kioptrix
            • Kioptrix2 WalkThrough
            • Kioptrix3 WalkThrough
            • Kioptrix4 WalkThrough
            • Kioptrix5 WalkThrough
          • Mission-Pumpkin
            • PumpkinGarden-WalkThrough
            • PumpkinFestival WalkThrough
            • PumpkinRaising WalkThrough
          • Symfonos
            • symfonos1 WalkThrough
            • symfonos2 WalkThrough
            • symfonos3 WalkThrough
            • symfonos5 WalkThrough
        • Wargames
          • Bandit
            • Bandit-WalkThrough
      • 面试问题
        • 面试问题
Powered by GitBook
On this page
  • 安装
  • 案例1
  • 案例2
  • A
  • B
  • 目录结构
  • apache+mod_ssl
  • 配置https
  • 配置php
  • 泛解析
  • 修改 header 头
  • Source & Reference
  1. Integrated
  2. Linux

httpd


Apache 与 httpd 的区别与关系

从我们仅仅web服务器使用者的角度说的话,它们是同一个东西。在 Apache 的网站上有两种安装包下载 httpd-2.0.50-i686-pc-linux-gnu.tar.gz 和 apache_1.3.33-i686-whatever-linux22.tar.gz 其实都是提供 Web 服务的,只是一个是早期版一个是新的版本模式。

httpd 是 apache 开源项目的一部分,如果只需要 web 服务器,现在只需安装 httpd2.* 就可以了。

早期的 Apache 小组,现在已经成为一个拥有巨大力量的 Apache 软件基金会,而 apache 现在成为 apache 基金会下几十种开源项目的标识。其中有一个项目做 HTTP Server,httpd 是 HTTP Server 的守护进程,在 Linux 下最常用的是 Apache,所以一提到 httpd 就会想到 Apache HTTP Server。

他们把起家的 apache 更名为 httpd,也更符合其 http server 的特性。以前 apache 的 http server 在 1.3 的时候直接叫 apache_1.3.37,现在 2.* 版本的都叫 httpd_2.2.3。在 Linux 下最常用的是 Apache,所以一提到 httpd 就会想到 Apache HTTP Server。


安装

centos 安装

yum -y install httpd

debian 下安装

apt-get install apache2

systemctl status apache2

# 删除
apt-get remove apache2

默认配置在 /etc/apache2/ 目录下

配置文件说明:

  • apache2.conf - apache2服务器的主配置文件

  • conf.d - 配置文件的附加片断

  • magic - 是有关mod_mime_magic模块的数据

  • ports.conf - 服务器监听IP和端口设置的配置文件

  • mods-available - 一些.conf和.load 文件

  • sites-available - 站点的配置文件

  • /var/www - 默认情况下发布的网页文件的目录


案例1

  • 配置 http 服务,以虚拟主机的方式建立一个 web 站点;

  • 配置文件名为 virthost.conf,放置在 /etc/httpd/conf.d 目录下;

  • 仅监听 192.168.2.22:8080 端口;

  • 使用 www.abc.com 作为域名进行访问;

  • 网站根目录为 /data/web_data ;

  • index.html 内容使用 fubuki!!fubuki!!fubuki!!fubuki!!.

安装

yum -y install httpd
yum -y install mod_ssl

配置虚拟主机文件

vim /etc/httpd/conf.d/virthost.conf

Listen 192.168.2.22:8080
<VirtualHost 192.168.2.22:8080>
	ServerName  www.abc.com
	DocumentRoot "/data/web_data"
	<Directory "/data/web_data">
		Require all granted
	</Directory>
</VirtualHost>

index.html 内容使用 fubuki!!fubuki!!fubuki!!fubuki!!

mkdir -p /data/web_data
vim /data/web_data/index.html

fubuki!!fubuki!!fubuki!!fubuki!!
httpd -t # 检查配置
setenforce 0
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
service httpd start

案例2

A

  • 配置 http 服务,以虚拟主机的方式创建 web 站点

  • 将 /etc/httpd/conf.d/ssl.conf 重命名为 ssl.conf.bak

  • 配置文件名为 virthost.conf,放置在 /etc/httpd/conf.d 目录下;

  • 配置 https 功能,https 所用的证书 httpd.crt、私钥 httpd.key 放置在 /etc/httpd/ssl 目录中(目录需自己创建);

  • 使用 www.abc.com 作为域名进行访问;

  • 网站根目录为 /data/web_data ;

  • 提供 http、https 服务,仅监听 192.168.1XX.22 的 IP 地址;

  • index.html 内容使用 fubuki!!fubuki!!fubuki!!fubuki!!;

安装

yum -y install httpd
yum -y install mod_ssl

配置虚拟主机文件

vim /etc/httpd/conf.d/virthost.conf

<VirtualHost 192.168.1xx.22:80>
	ServerName  www.abc.com
	DocumentRoot "/data/web_data"
	<Directory "/data/web_data">
		Require all granted
	</Directory>
</VirtualHost>

Listen 192.168.1XX.33:443
<VirtualHost 192.168.1xx.22:443>
	ServerName  www.abc.com
	DocumentRoot "/data/web_data"

	SSLEngine on
	SSLCertificateFile /etc/httpd/ssl/httpd.crt
	SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

	<Directory "/data/web_data">
		Require all granted
	</Directory>
</VirtualHost>

!!!!注意,必须要改名,大坑

mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak

index.html 内容使用 fubuki!!fubuki!!fubuki!!fubuki!!

mkdir -p /data/web_data
vim /data/web_data/index.html

fubuki!!fubuki!!fubuki!!fubuki!!

创建证书

cd /etc/pki/CA/private
openssl genrsa 2048 > cakey.pem
openssl req -new -x509 -key cakey.pem > /etc/pki/CA/cacert.pem

cd /etc/pki/CA
touch index.txt	# 索引文件
touch serial	# 给客户发证编号存放文件
echo 01 > serial

mkdir /etc/httpd/ssl
cd /etc/httpd/ssl
openssl genrsa 1024 > httpd.key
openssl req -new -key httpd.key > httpd.csr
openssl ca -days 365 -in httpd.csr > httpd.crt

# 查看 openssl 证书数据库文件
cat /etc/pki/CA/index.txt
httpd -t	# 检查配置
setenforce 0
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
service httpd start
curl http://www.abc.com
curl https://www.abc.com

B

  • 配置 http 服务,以虚拟主机的方式创建 web 站点

  • 将 /etc/httpd/conf.d/ssl.conf 重命名为 ssl.conf.bak

  • 配置文件名为 virthost.conf,放置在 /etc/httpd/conf.d 目录下;

  • 配置 https 功能,https 所用的证书httpd.crt、私钥 httpd.key 放置在 /etc/httpd/ssl 目录中(目录需自己创建,httpd.crt、httpd.key 均文件从 serverA 复制);

  • 使用 www.abc.com 作为域名进行访问;

  • 提供 http、https 服务,仅监听 192.168.1XX.33 的地址.

安装

yum -y install httpd
yum -y install mod_ssl

配置虚拟主机文件

vim /etc/httpd/conf.d/virthost.conf

<VirtualHost 192.168.1xx.33:80>
	ServerName  www.abc.com
	DocumentRoot "/data/web_data"
	<Directory "/data/web_data">
		Require all granted
	</Directory>
</VirtualHost>

Listen 192.168.1XX.33:443
<VirtualHost 192.168.1xx.33:443>
	ServerName  www.abc.com
	DocumentRoot "/data/web_data"

	SSLEngine on
	SSLCertificateFile /etc/httpd/ssl/httpd.crt
	SSLCertificateKeyFile /etc/httpd/ssl/httpd.key

	<Directory "/data/web_data">
		Require all granted
	</Directory>
</VirtualHost>

mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak

index.html 内容使用 fubuki!!fubuki!!fubuki!!fubuki!!

mkdir -p /data/web_data
vim /data/web_data/index.html

fubuki!!fubuki!!fubuki!!fubuki!!
mkdir /etc/httpd/ssl
cd /etc/httpd/ssl

scp root@192.168.1xx.22:/etc/httpd/ssl/httpd.key /etc/httpd/ssl/httpd.key
scp root@192.168.1xx.22:/etc/httpd/ssl/httpd.crt /etc/httpd/ssl/httpd.crt
httpd -t	# 检查配置
setenforce 0
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload
service httpd start

目录结构

apache2

/etc/apache2

  • apache2.conf : 这是服务器的主要配置文件。几乎所有的配置都可以在这个文件中完成,不过为了简单起见,建议使用单独的指定文件。这个文件将配置默认值,是服务器读取配置细节的中心点。

  • ports.conf : 这个文件用于指定虚拟主机应该监听的端口。如果你在配置 SSL,请务必检查这个文件是否正确。

  • conf.d/ : 这个目录用于控制 Apache 配置的特定方面。例如,它经常被用来定义 SSL 配置和默认安全选择。

  • sites-available/ : 这个目录包含了所有定义不同网站的虚拟主机文件。这些文件将确定哪些内容被服务于哪些请求。这些是可用的配置,而不是活动的配置。

  • sites-enabled/ : 这个目录确定了实际使用的虚拟主机定义。通常,这个目录由 "sites-available"目录中定义的文件的符号链接组成。

  • mods-[enabled,available]/ : 这些目录在功能上与网站目录类似,但它们定义了可以选择加载的模块。


apache+mod_ssl

  • 配置 http+https 服务,建立一个 web 站点;

  1. 安装

yum -y install httpd
yum -y install mod_ssl
  1. 使用 www.abc.com 作为域名进行访问;

nslookup www.abc.com
  1. 网站根目录为 /var/www/html;

vim /etc/httpd/conf/httpd.conf

	DocumentRoot "/var/www/html"
	ServerName  xx.xx.xx.xx:80
  1. Index.html 内容使用 fubuki!fubuki!fubuki!fubuki!;

vim var/www/html/index.html

fubuki!fubuki!fubuki!fubuki!
service httpd restart 或 systemctl start httpd
记得关防火墙
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
  1. 配置 https 服务使原站点能使用 https 访问.

# 查看证书密钥位置
sed -n '/^SSLCertificateFile/p;/^SSLCertificateKeyFile/p '/etc/httpd/conf.d/ssl.conf

# 删除原来的密钥
cd /etc/pki/tls/private/
rm -f localhost.key

# 新建密钥文件
openssl genrsa 1024 > localhost.key

# 删除原来的证书
cd ../certs
rm -rf localhost.crt

# 新建证书文件
openssl req -new -x509 -days 365 -key ../private/localhost.key -out localhost.crt

防火墙放行 https,重启服务,测试

设置 SELINUX 状态为 Disabled;

setenforce 0
vim /etc/selinux/config

SELINUX=disabled

配置https

使用 Let’s Encrypt 直接上 https

yum install -y yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
yum install -y certbot python2-certbot-apache

certbot --apache
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --reload

mod_ssl 为 linux 提供 web 证书

cd /etc/pki/CA/private
openssl genrsa 2048 > cakey.pem
openssl req -new -x509 -key cakey.pem > /etc/pki/CA/cacert.pem

cd /etc/pki/CA
touch index.txt     # 索引问文件
touch serial        # 给客户发证编号存放文件
echo 01 > serial

mkdir /etc/httpd/ssl
cd /etc/httpd/ssl
openssl genrsa 1024 > httpd.key
openssl req -new -key httpd.key > httpd.csr
openssl ca -days 365 -in httpd.csr > httpd.crt

# 使用 cat /etc/pki/CA/index.txt 查看 openssl 证书数据库文件
cat /etc/pki/CA/index.txt

mod_ssl 为 windows 提供 web 证书

cd /etc/pki/CA/private
openssl genrsa 2048 > cakey.pem
openssl req -new -x509 -key cakey.pem > /etc/pki/CA/cacert.pem

cd /etc/pki/CA
touch index.txt   # 索引问文件
touch serial      # 给客户发证编号存放文件
echo 01 > serial

cd
openssl genrsa 1024 > httpd.key
openssl req -new -key httpd.key > httpd.csr
openssl ca -days 365 -in httpd.csr > httpd.crt

openssl pkcs12 -export -out server.pfx -inkey httpd.key -in httpd.crt
# 自己把 server.pfx 导出给 windows2008 主机

向 windows CA 服务器申请证书

Openssl genrsa 2048 > httpd.key
openssl req -new -key httpd.key -out httpd.csr

通过这个 csr 文件在内部的 windows CA 服务器上申请证书


配置php

若之前安装过其他版本 PHP,先删除
yum remove php*

rpm 安装 PHP7 相应的 yum 源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php70w php70w-fpm

php -v                # 查看PHP版本

service php-fpm start # 要运行 PHP 网页,要启动 php-fpm 解释器
vim /etc/httpd/conf/httpd.conf

# 将Require all denied 改为Require all granted
<Directory />
    AllowOverride none
    Require all granted
</Directory>

# 增加一行 AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php

# 增加索引页 index.php,在 DirectoryIndex index.html 后面 增加索引页 index.php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

检查配置文件 httpd.conf 的语法是否正确

apachectl -t

检测 php 是否正常解析

echo "<?php phpinfo(); ?>"  > /var/www/html/1.php

service httpd restart
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

访问 机器相应ip/1.php


泛解析

<VirtualHost 192.168.1.1>
    ServerName "www.ffffffff0x.com"       # 默认域名
    ServerAlias *.ffffffff0x.com          # 用*表示泛域名
</VirtualHost>

修改 header 头

以 debian 为例,修改 /etc/apache2/conf-available/security.conf

将內容中 ServerTokens 对应的值改为 Prod

-- ServerTokens OS
++ ServerTokens Prod

前后区别


Source & Reference

PreviousIptablesNextLAMP

Linux下Apache与httpd的区别与关系
Apache对域名的泛解析方法集锦