零、需求
a.符合合规性检查
b.开启域名访问80
c.禁止IP直接访问80
d.IP直接访问80跳转指定HTTP、HTTPS
e.HTTP跳转HTTPS(具体情况使用,老游戏不支持HTTPS)
项目文件:C:\BF\Xampp\apache\conf\extra
用到的文件:
httpd-ssl.conf
httpd-vhosts.conf
用到的证书请自备。
一、配置SSL
打开C:\BF\Xampp\apache\conf\extra\httpd-ssl.conf
httpd-ssl.conf,在最后添加一下代码:
<VirtualHost _default_:443>
DocumentRoot "C:\BF\Xampp\htdocs"
ServerName bfl.域名.cn:443
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile "king_ssl/域名.cn.crt"
SSLCertificateKeyFile "king_ssl/域名.cn.key"
</VirtualHost>
这里的根目录是在C:\BF\Xampp\apache
即证书文件应该放在:C:\BF\Xampp\apache\king_ssl
二、允许域名:80访问
C:\BF\Xampp\apache\conf\extra\httpd-vhosts.conf
httpd-vhosts.conf,在最后添加一下代码:
<VirtualHost *:80>
DocumentRoot "C:\bf\xampp\htdocs"
ServerName bfl.域名.cn
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
三、配置禁止IP访问(建议步骤四)
在 xampp 的安装目录下,打开 /apache/conf/extra/httpd-vhosts.conf,在最后添加一下代码:
<VirtualHost *:80>
ServerName 106.x.x.x
<Directory />
deny from ALL
</Directory>
</VirtualHost>
其中,ServerName 106.*.*.* 是你的服务器 IP 地址,之后重启 Apache,再次通过 IP 直接访问你的网站,就提示错误。不能访问。使用可以配置ServerAdmin admin@域名.com 使用。
四、推荐的方法是IP访问直接跳转
C:\BF\Xampp\apache\conf\extra\httpd-vhosts.conf
httpd-vhosts.conf
<VirtualHost *:80>
ServerName 106.x.x.x
ServerAlias
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^blog.域名.cn$
RewriteRule ^/(.*)$ http://blog.域名.cn/$1 [R=301,L]
</IfModule>
</VirtualHost>
五、步骤二+步骤四一起使用
C:\BF\Xampp\apache\conf\extra\httpd-vhosts.conf
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:\bf\xampp\htdocs"
ServerName bfl.域名.cn
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName 106.x.x.x
ServerAlias
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^blog.域名.cn$
RewriteRule ^/(.*)$ http://blog.域名.cn/$1 [R=301,L]
</IfModule>
</VirtualHost>
六、跳转HTTPS
<VirtualHost *:80>
ServerName 域名.cn
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
</VirtualHost>
七、提示
通过proxy方式跳转,在Windows下亲测不行,报错。
ServerAdmin admin@域名.com,会在报错时显示。
<VirtualHost *:80>
ServerAdmin admin@域名.com
<Directory />
</Directory>
</VirtualHost>
解析 DocumentRoot 为服务器访问的目录; ServerName 为刚才设置的虚拟域名。