首先你需要配置好httpd服务,iptables防火墙要打开443端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
然后输入以下指令
第二步yum install mod_ssl openssl
rpm -qa| grep mod_ssl
rpm -qa| grep openssl
安装完成后会生成一个
/etc/httpd/conf.d/ssl.conf文件
这里给大家提供一个免费的颁发ssl证书的网站
Certbot Instructions | Certbot
按照网站指引输入指令
当你到达
这一步时停止
第三步输入
vi /etc/httpd/conf/httpd.conf
打开apache配置文件
找到SeverName部分按照如下格式添加,example输入你自己的域名
关键时刻来了
找到httpd.conf文件中的
按照如下格式书写,一点也不能更改格式,少个空格都不行!!!!!!!
# 'Main' server configuration # # The directives in this section set up the values used by the 'main' # server, which responds to any requests that aren't handled by a #definition. These values also provide defaults for # any containers you may define later in the file. # # All of these directives may appear inside containers, # in which case these default settings will be overridden for the # virtual host being defined. # NameVirtualHost 111.222.333.444:80 ServerAdmin root@localhost documentRoot /var/www/html ServerName www.gangcaishudeyuming.xyz ErrorLog logs/error_log TransferLog logs/access_log
域名和ip地址写你自己的
紧接着在loadmodules段按照如下格式写
保存退出
输入:
systemctl restart httpd
如果重启成功啧代表修改配置成功,如果重启失败提示语法错误说明你刚刚操作错了
如果重启成功,那么回到第二部的最后一步使用certbot给域名安装ssl证书就会成功了,如果成功提示让你选择你的域名,那么代表安装成功,输入对应数字即可选择安装的域名,certbot会自动申请证书
第五步使用FileZilla软件或者其他什么能够操作远程操作服务器文件的软件,或者你用指令啥的都可以。
将/etc/letsencrypt/live/这个目录里的文件证书转移到一个方便寻找的地方
以下四个证书都要转出
cert.pem ->chain.pem ->fullchain.pem ->privkey.pem ->
紧接着编辑ssl.conf文件
vi /etc/httpd/conf.d/ssl.conf
找到如下位置,输入你刚才转移证书所到的那个地址
# General setup for the virtual host, inherited from global configuration documentRoot "/var/www/html/" ServerName www.nideyuming.com:443 . . . SSLCertificateFile /etc/letsencrypt/live/fullchain.pem . . . SSLCertificateKeyFile /etc/letsencrypt/live/privkey.pem . . .
如果以上内容你都正确操作,那么这时候重启httpd服务
systemctl restart httpd
试着用https的方法访问你的域名
https://www.xxxxx.com
如果成功,则恭喜你配置成功了



