The Apache website deploys an SSL certificate to enable https access and forces http to jump to https.

Centos server blog website installation tutorial can be found at: Centos 7. PHP, Apache environment, and successfully installed WordPress blog website. https://blog.csdn.net/qq_35379989/article/details/130502340?spm=1001.2014.3001.5501 This tutorial is divided into two parts: SSL certificate installation and forcing http to jump to https.

1. Install SSL certificate and enable https access

(1) Install mod_ssl openssl

yum install mod_ssl openssl

(2)Download/generate certificate

If you purchase a domain name from domestic service providers such as Baidu Cloud/Alibaba Cloud/Tencent Cloud, you can apply for a free certificate

For example, Tencent Cloud, select My Certificate->Free Certificate->Apply for a Free Certificate in the console

After applying, select the Apache format to download.

 (3) Upload the certificate file to the server

First, give permissions to the folder we want to upload so that FTP can upload directly

chmod 777 -R /etc/pki/tls

At this time, open our FTP software, enter /etc/pki/tls, upload the certificate in crt file format to the certs folder, and upload the secret key file in key format to the private folder.

(4) Enable the newly uploaded ssl certificate

vim /etc/httpd/conf.d/ssl.conf

Press i to enter editing, press esc to exit editing, and change the following two places to the certificate and secret key file names you uploaded in (3)

 After the modification is completed, press: and then enter wq! to complete saving the modified content.

(5) Restart apache to make the certificate effective

service httpd restart

2. Force http to jump to https

(1) Enable apache’s .htaccess configuration

vim /etc/httpd/conf/httpd.conf

Change None in AllowOverride None about .htaccess to All, as shown below:

 (2) Create .htaccess file

The file contains the following content:

RewriteEngine on          
RewriteBase /             
RewriteCond %{SERVER_PORT} !^443$    
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]  

(3) Upload the .htaccess file to the root directory of the website, such as /var/www/html or www, etc.

(4) Restart apache to take effect

vim /etc/httpd/conf/httpd.conf

Guess you like

Origin blog.csdn.net/qq_35379989/article/details/130605520