为了防止恶意域名绑定到自己的服务器ip上以及直接通过ip访问方式访问。我们可以通过apache配置可以实现这一目的,具体操作步骤如下。
第一步,httpd.conf配置设置
启用虚拟主机、ssl、重写模块
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule ssl_module modules/mod_ssl.so
禁用根目录访问
AllowOverride None
Require all denied
允许htdocs目录访问
DocumentRoot "/usr/local/httpd/htdocs"
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named
explicitly --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
#
http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
# cache
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all denied
参考文档https://blog.csdn.net/zouqingfang/article/details/52366399