Centos 7 Nginx Letsencrypt Https And Https Both Active


Centos 7 Nginx Letsencrypt Https And Https Both Active

Introduction

Are you overwhelmed with the number of steps required to set up an SSL certificate in CentOS 7? If so, this article is the perfect guide for you! We will cover both issuing the certificate using Let’s Encrypt, and configuring Nginx to use the HTTPS protocol. By the end of this article, you will be able to access your website over both HTTPS and HTTP protocols.

Many users opt against HTTPS because of the tedious setup involved. With the popularity of Let’s Encrypt, setting up HTTPS has become much easier. Many hosting providers offer free Let’s Encrypt certificates for their users, but if you’re running your own server, then you will need to install it yourself.

Installing Let’s Encrypt

Let’s Encrypt is a free and open source certificate authority. It lets users create, install and maintain digital certificates for secure communications on the internet. It is run by the Internet Security Research Group (ISRG), a nonprofit organization.

First, you need to download the Let’s Encrypt client. For CentOS 7, you can use Certbot, which is a command line tool for automating the certificate management process. To download it, run the following command in your terminal:

sudo yum install certbot

You may be asked to confirm the installation. Press ‘y’ and then enter when prompted.

The next step is to issue the certificate. To do this, run the following command as root:

certbot --nginx

The command will ask you to enter your email address, agree to the terms and conditions, and then enter the domain name of your website. Make sure the domain is configured to point to the server’s IP address. Certbot will then create the certificate.

Configuring Nginx for HTTPS

Once the certificate is issued, you need to configure Nginx to use it. To do this, open the Nginx configuration file. It is usually in /etc/nginx/nginx.conf. Now, add the following lines:

server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live//fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live//privkey.pem;
}

Replace with the domain name of your website. Once you save the configuration file, restart Nginx. To do this, run the following command in your terminal:

systemctl restart nginx

Using a Custom Certificate

If you don’t want to use a Let’s Encrypt certificate, then you can set up a custom certificate. First, you need to generate the certificate and key. You can use the OpenSSL command line tool for this. To generate a self-signed certificate, run the following command in your terminal:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -out .crt -keyout .key

Replace and with the names of the certificate and private key. The command will create a certificate and key with the specified names. You can then configure Nginx to use the certificate.

First, copy the certificate and key files to your server. Then open the Nginx configuration file and add the following lines:

server {
listen 443 ssl;
ssl_certificate .crt;
ssl_certificate_key .key;
}

Replace and with the names of the certificate and private key. Be sure to include the .crt and .key extensions. Now save the configuration file, and restart Nginx with the following command:

systemctl restart nginx

Enabling HTTP and HTTPS

By default, Nginx is configured to listen on port 80 for HTTP and port 443 for HTTPS. This means you can access your website over both HTTP and HTTPS protocols. To enable both protocols, open the Nginx configuration file and add the following lines:

server {
listen 80;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live//fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live//privkey.pem;
}

Replace with the website’s domain name. Once you save the configuration file, restart Nginx with the command mentioned above.

FAQs

Q: Is it necessary to use an SSL certificate?

A: Yes, it is necessary to use an SSL certificate when running a website. This is because SSL provides encryption between the server and the client, which improves security and privacy. It also gives your website credibility, as visitors can be assured that their data is safe.

Q: What is the Let’s Encrypt client?

A: The Let’s Encrypt client is a command line tool used for issuing and managing SSL certificates. It automates the process and makes it easier to install certificates quickly.

Conclusion

In this article, we have covered the steps required to set up an SSL certificate in CentOS 7 using Let’s Encrypt and Nginx. We have also looked at a few FAQs about SSL and Let’s Encrypt. While setting up the certificate can seem daunting, the process is actually quite straightforward. We hope this article has been helpful to you.

Thank you for reading this article. Please read other articles for more information and helpful tips.