Web 容器
1. Windows 安装
# 准备安装包:httpd-2.4.41-o102s-x64-vc14-r2.zip
# 解压到D盘根目录:修改配置文件
D:\Apache24\conf\httpd.conf
Define SRVROOT "D:\Apache24"
# 在530行左右,使用默认的ssl配置文件
<IfModule ssl_module>
Include conf/extra/httpd-ssl.conf
[[Include]] conf/extra/httpd-ahssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
将如下配置文件从ssl目录复制到外面一份:
# 安装服务:
D:\Apache24\bin>httpd.exe -k install -n apache24
Installing the 'apache24' service
The 'apache24' service is successfully installed.
Testing httpd.conf....
D:\Apache24\bin>
# 删除服务:
sc delete apache24
在阿里云申请免费证书,得到如下三个文件
2. CentOS Install
# 安装软件
yum install mod_ssl openssl httpd -y
# 修改配置文件/etc/httpd/conf.d/ssl.conf,将上述文件传到指定的位置上,然后修改如下配置值即可。
SSLCertificateFile "public.crt证书路径"
SSLCertificateKeyFile ".key证书路径"
SSLCertificateChainFile "chain.crt证书路径"
3. Config error page.
在访问异常的时候展示错误页面。
3.1. Demo1
内容根据需求写,如果404.html的小于512字节的话,那么IE会认为这个错误页面不够“友好”,会忽视掉的!
必须放置在网站根目录(www/)中
# 在httpd.conf中设置对目录开启。
AllowOverride All
# 然后在目录里放一个.htaccess(.htaccess),添加:
errorDocument 404 /404.php
3.2. Demo2
# 修改 httpd.conf,找到:
[[ErrorDocument]] 500 "The server made a boo boo."
[[ErrorDocument]] 404 /missing.html
[[ErrorDocument]] 404 "/cgi-bin/missing_handler.pl"
[[ErrorDocument]] 402 http://www.example.com/subscription_info.html
# 去掉注释,添加内容
ErrorDocument 404 /error.php
• 注意不要将404错误转向到网站主页。 • 如果一个页面的内容小于512b,IE会认为该不会成功返回该错误页面。 • 切记不要使用绝对URL。常情况返回的是404状态码,而使用URL形式则返回的是200状态码。
4. 禁止浏览目录
<Directory "${SRVROOT}/htdocs">
# 去掉 如下配置 中间的 Indexes 即可
# Options Indexes FollowSymLinks
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
5. Apache2 http 配置伪静态
一、加载rewrite.so模块,默认是不加载的
1、rewrite.so模块默认路径在:/usr/lib/apache2/modules/mod_rewrite.so
2、apache2的主配置文件:apache2.conf会引用/etc/apache2/mods-enabled/下的所在的*.conf和*.load
3、/etc/apache2/mods-enabled/又软连接到/etc/apache2/mods-available/
4、进入/etc/apache2/mods-available/,新建文件rewrite.load,并加入“LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so”来加载rewrite.so模块
5、进入/etc/apache2/mods-enabled/,建立软连接,执行命令:$ ln -s ../mods-available/rewrite.load rewrite.load
二、配置apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AllowOverride All
Requireall granted
# AllowOverride None
# Require all granted
</Directory>