没有不值得去解决的问题,也没有不值得去学习的技术!

How to Configure SSL Support for Apache Virtual Hosts on CentOS 6.5 64-bit

Figure 12: View SSL certificate information

1. SSL certificate installation environment overview:

Operating System: CentOS 6.5 64-bit

Apache 2.2.15

WoSign free SSL certificate

2. Network environment requirements

http://api.ygt.cm can be accessed normally from the external network

3. Obtain the SSL certificate

After successfully applying for a certificate from WoSign, you will receive a password-protected compressed archive. Entering the certificate password and extracting it yields five files, as shown in Figure 0:
for Apache, for IIS, for Nginx, for Other Server, for Tomcat.
These are the different certificate formats. Apache requires the certificate in the for Apache format, as shown in Figure 1.

Figure 1: These are the different certificate formats; Apache requires the certificate in the for Apache format
Figure 1: These are the different certificate formats; Apache requires the certificate in the for Apache format

4. Extract the certificate files

Extracting the for Apache file reveals three files. These include the public key, private key, and certificate chain, as shown in Figure 2.

Figure 2: Extracting the for Apache file reveals three files, including the public key, private key, and certificate chain
Figure 2: Extracting the for Apache file reveals three files, including the public key, private key, and certificate chain

5. Locate the ssl.conf file in the conf.d directory under the Apache installation directory. If it does not exist, Apache has not compiled the SSL module, and you need to reinstall mod_ssl.

6. Run: yum install mod_ssl, as shown in Figure 3.

Figure 3: Run: yum install mod_ssl
Figure 3: Run: yum install mod_ssl

7. Upload the three files via FTP to the api.ygt.cm directory, as shown in Figure 4.0.

Figure 4.0: Upload the three files via FTP to the api.ygt.cm directory
Figure 4.0: Upload the three files via FTP to the api.ygt.cm directory

7.1. Copy the three files to the appropriate directories under /etc/httpd/, as shown in Figure 5.

Figure 5: Copy the three files to the appropriate directories under /etc/httpd/
Figure 5: Copy the three files to the appropriate directories under /etc/httpd/

7.2. Open the ssl.conf file in the conf.d directory under the Apache installation directory.

Locate the following configuration directives in the configuration file:

Modify the encryption protocols as follows, as shown in Figure 4:

SSLProtocol all -SSLv2 -SSLv3

Figure 4: SSLProtocol all -SSLv2 -SSLv3
Figure 4: SSLProtocol all -SSLv2 -SSLv3

7.3. Configure the server certificate public key to this path, as shown in Figure 6:

SSLCertificateFile /etc/httpd/conf/ssl.crt/api.ygt.cm.crt Certificate public key

Figure 6: Certificate public key
Figure 6: Certificate public key

7.4. Configure the server certificate private key to this path:

SSLCertificateKeyFile /etc/httpd/conf/ssl.key/api.ygt.cm.key Certificate private key

7.5. Configure the server certificate chain to this path:

SSLCertificateChainFile /etc/httpd/conf/ssl.crt/api.ygt.cm.root_bundle.crt Certificate chain

7.6. Edit /etc/httpd/conf.d/ssl.conf in the virtual host, as shown in Figure 7.

First, comment out all configurations between the following tags:

# <VirtualHost _default_:443>
# </VirtualHost>

Figure 7: Comment out all configurations between the VirtualHost tags
Figure 7: Comment out all configurations between the VirtualHost tags

7.7. Configure the virtual host by making the appropriate settings based on the original default virtual host configuration, as shown in Figure 7.1.

Figure 7.1: Configure the virtual host by making the appropriate settings based on the original default virtual host configuration
Figure 7.1: Configure the virtual host by making the appropriate settings based on the original default virtual host configuration

8. Run service httpd restart to restart the Apache server.

9. Restart error:

Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 10.171.221.184 for ServerName
As shown in Figure 8.

Figure 8: Restart error: Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name
Figure 8: Restart error: Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name

10. Edit the httpd.conf file, as shown in Figure 9.

Find #ServerName www.example.com:80 and change it to: ServerName www.ygt.cm:80

Figure 9: Find #ServerName www.example.com:80 and change it to: ServerName www.ygt.cm:80
Figure 9: Find #ServerName www.example.com:80 and change it to: ServerName www.ygt.cm:80

11. Restart the Apache server again. The “Starting httpd: httpd: Could not reliably determine the server’s fully qualified domain name, using 10.171.221.184 for ServerName” error disappears;
as shown in Figure 9.1.

Figure 9.1: The "using 10.171.221.184 for ServerName" error disappears
Figure 9.1: The “using 10.171.221.184 for ServerName” error disappears

12. There is still this error:

[Mon Aug 31 15:15:25 2015] [warn] VirtualHost 121.40.99.104:443 overlaps with VirtualHost 121.40.99.104:443, the first has precedence, perhaps you need a NameVirtualHost directive

As shown in Figure 10.

Figure 10: the first has precedence, perhaps you need a NameVirtualHost directive
Figure 10: the first has precedence, perhaps you need a NameVirtualHost directive

13. Edit /etc/httpd/httpd.conf

NameVirtualHost Server public IP:80

Figure 10.1: NameVirtualHost Server public IP:80
Figure 10.1: NameVirtualHost Server public IP:80

14. Restart Apache; no errors are reported, as shown in Figure 11.

Figure 11: Restart Apache; no errors are reported
Figure 11: Restart Apache; no errors are reported

15. Check the web page and find that the API URL now supports HTTPS, as shown in Figures 12 and 12.1.

Figure 12: View SSL certificate information
Figure 12: View SSL certificate information
Figure 12.1: Certificate viewer, SSL client certificate
Figure 12.1: Certificate viewer, SSL client certificate

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系