惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
博客园 - 【当耐特】
月光博客
月光博客
Vercel News
Vercel News
D
Docker
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
博客园 - 聂微东
小众软件
小众软件
Y
Y Combinator Blog
腾讯CDC
L
LangChain Blog
The GitHub Blog
The GitHub Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
T
The Blog of Author Tim Ferriss

Comments for ScriptsTown

How to Get Site and Secret Key for Google reCAPTCHA Top 5 Marketing Tips and Ideas to Grow your Business
How to Setup Cloudflare SSL and Configure Origin Certific...
ScriptsTown · 2021-06-22 · via Comments for ScriptsTown

In this guide, we will set up Cloudflare SSL and configure the Origin Certificate for the Apache server. Follow the simple steps to install SSL on your website.

In case you are using cPanel-powered web hosting, then you may want to read this guide where we install a Cloudflare SSL certificate using cPanel.

Here, we assume you have sudo user access to your server. Now, create a directory for storing the certificate and the key.

> sudo mkdir /etc/apache2/ssl

Now, to enable SSL in Apache, run the following command:

> sudo a2enmod ssl

Restart the Apache server for this to take effect.

> sudo systemctl restart apache2

Point to Cloudflare’s nameservers

Now, you need to sign up for a Cloudflare account. There, you will need to provide your domain name (let’s say “example.com”). After, it will ask for updating the nameservers of your domain registrar. Once, you update the nameservers that Cloudflare provides and your domain points to Cloudflare nameservers, you can proceed to the next steps.

Get Cloudflare Origin Certificate and Private Key

In the Cloudflare dashboard, navigate to “SSL/TLS”, then under “Origin Server”, click on “Create Certificate”.

Cloudflare - SSL - Origin Server - Create Certificate
Cloudflare – SSL – Origin Server – Create Certificate

Select “Generate a private key and CSR with Cloudflare” and set “Private key type” to “RSA (2048)”. Set “Certificate Validity” to “15 years” (These steps should be done by default.). Then, click “Create”.

Cloudflare - Origin Certificate - Private Key and CSR
Cloudflare – Origin Certificate – Private Key and CSR

Now, you will see your “Origin Certificate” and “Private Key”. Make sure to copy the content of both separately.

Cloudflare - Origin Certificate and Private Key
Cloudflare – Origin Certificate and Private Key

Here, the “Origin Certificate” will be something like this:

-----BEGIN CERTIFICATE-----
........
........
........
-----END CERTIFICATE-----

And, “Private Key” will be something like:

-----BEGIN PRIVATE KEY-----
........
........
........
-----END PRIVATE KEY-----

Create Files to Store Origin Certificate and Private Key

Now, we will need to create two files under “/etc/apache2/ssl” directory to store the certificate and key.

Create a new file under “/etc/apache2/ssl” directory to store the “Origin Certificate”. Here, you can replace “example.com” with your domain name.

> sudo nano /etc/apache2/ssl/example.com.pem

Paste the content of the “Origin Certificate” to the file and save it (Ctrl + X and Y to save).

Next, create a new file under “/etc/apache2/ssl” directory to store the “Private Key”.

> sudo nano /etc/apache2/ssl/example.com.key

Paste the content of the “Private Key” to the file and save it.

Now, you can verify if the files are there using the command:

> sudo ls /etc/apache2/ssl/

Make sure, you see both files “example.com.pem” and “example.com.key”.

Now, change the permission of this directory using the command:

> sudo chmod -R 655 /etc/apache2/ssl

Also, change the ownership to “www-data”.

> sudo chown -R www-data:www-data /etc/apache2/ssl

Configure Virtual Host for Cloudflare SSL Certificate

In your Apache’s virtual host configuration file, we need to turn on SSL and also, point to the certificate files.

Open Apache’s virtual host file. Here, we are using the nano editor.

> sudo nano /etc/apache2/sites-available/example.com.conf

In this file, you will see something like this:

<VirtualHost *:80> 
	ServerName example.com
        DocumentRoot /var/www/html
</VirtualHost>

Change port 80 to 443 for SSL. Also, turn on SSLEngine and point to the certificate and key file. Then, it will look like this:

<VirtualHost *:443> 
	ServerName example.com
        DocumentRoot /var/www/html

	SSLEngine on
	SSLCertificateFile /etc/apache2/ssl/example.com.pem
	SSLCertificateKeyFile /etc/apache2/ssl/example.com.key
</VirtualHost>

To activate this virtual host file, you can run the command:

> sudo a2ensite example.com.conf

To test the configuration, run the following command:

> apachectl configtest

Lastly, restart Apache or reload Apache configuration.

> sudo service apache2 reload

Now, you can test your website by visiting: https://example.com/

Also, the SSL installation and new expiration date can be verified by different tools available online. Lastly, you may want to force all requests to https.

If you face any trouble when setting up SSL, then you can drop a message to us using our contact form. We will get back to you via email as soon as possible.

We also have a guide on how to install the Let’s Encrypt SSL certificate for your domain which is also a free alternative to the Cloudflare SSL.