Appearance

Appearance
Apache 中文文档 - Apache HTTP 服务器 2.4 文档
# 1.打开apache配置文件
$ vim /etc/httpd/conf/httpd.conf
# 2.将下面两行代码添加到 Apache 配置文件底部:
ServerSignature Off
ServerTokens Prod
# ServerSignature Off 目的是让Apache网站服务器在所有错误页面上隐藏Apache版本信息。
# ServerTokens Prod 目的是在HTTP响应头中将服务器标记压缩到最小,否则Apache服务器将仍然在HTTP回应头部包含详细的服务器标记,这会泄漏Apache的版本号。
# 3.重启apache服务
$ systemctl restart httpd.service
参考链接:
/home/kevin/www/html
目录$ cd /home/kevin/www/
$ mkdir html
$ vim /etc/httpd/conf/httpd.conf
# 把其中的 /var/www/html 改成 /home/kevin/www/html
# 把其中的 /var/www 改成 /home/kevin/www/
$ systemctl restart httpd.service
若出现 403 Forbidden
错误,为文件夹赋予读取权限:
$ chmod -R 755 /home/kevin
# 这里只改`/home/kevin/www/`不行,必须修改`/home/kevin`
参考链接:Apache设置禁止访问网站目录
$ vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks
,去掉 Indexes
...
<Directory "/home/kevin/www/html">
#
# 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.2/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:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
$ systemctl restart httpd.service
参考链接:
$ mv -i /home/kevin/cert/etc/httpd
# 在Apache安装目录中新建cert目录,并将证书、证书链文件和密钥文件拷贝到cert目录中。
# 由于root不能登陆ftp,这里先将证书上传到kevin文件夹,再通过root账户转移文件。
yum install mod_ssl openssl openssl-devel httpd-devel;
$ vim /etc/httpd/conf/httpd.conf
# 删除行首的配置语句注释符号“#”,加载mod_ssl.so模块启用SSL服务。(Apache默认是不启用该模块的)
# 如果找不到该配置,请重新编译mod_ssl模块。
LoadModule ssl_module modules/mod_ssl.so
# 加载模块配置文件
Include conf.modules.d/*.conf
$ vim /etc/httpd/conf.d/ssl.conf
# 注意:需注释掉原来就存在的相应代码
<VirtualHost *:443>
ServerName xukaiwen.com
DocumentRoot "/home/kevin/www/html"
SSLEngine on
# 添加SSL协议支持协议,去掉不安全的协议:
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件:
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
SSLCertificateFile /etc/httpd/cert/1877027_www.xukaiwen.com_public.crt
SSLCertificateKeyFile /etc/httpd/cert/1877027_www.xukaiwen.com.key
SSLCertificateChainFile /etc/httpd/cert/1877027_www.xukaiwen.com_chain.crt
</VirtualHost>
$ systemctl restart httpd.service
# 在httpd.conf文件中的<VirtualHost *:80> </VirtualHost>中间添加以下重定向代码:
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*)$ https://%{SERVER_NAME}/$1 [L,R]
</VirtualHost>