<\/span><\/h2>\nIn this tutorial, we will install and use Nginx web server. It is a free, open-source, and high-performance web server known for its great performance, stability, low resource usage, extensive feature set, and simple configuration. Nginx is available in the official Ubuntu 18.04 repositories and the installation is pretty easy. Run the following command to install it on your server<\/p>\n
apt -y install nginx<\/pre>\nOnce the Nginx web server is installed, it should be automatically started. You can check its status with the following command<\/p>\n
systemctl status nginx<\/pre>\nOutput:<\/p>\n
\u00e2 nginx.service - A high performance web server and a reverse proxy server\r\n Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)\r\n Active: active (running) since Wed 2019-07-24 02:40:17 CDT; 1min 8s ago\r\n Docs: man:nginx(8)\r\n Process: 28420 ExecStart=\/usr\/sbin\/nginx -g daemon on; master_process on; (code=exited, status=0\/SUCCESS)\r\n Process: 28419 ExecStartPre=\/usr\/sbin\/nginx -t -q -g daemon on; master_process on; (code=exited, status=0\/SUCCESS)\r\n Main PID: 28421 (nginx)\r\n Tasks: 3 (limit: 2321)\r\n CGroup: \/system.slice\/nginx.service\r\n \u00e2\u00e228421 nginx: master process \/usr\/sbin\/nginx -g daemon on; master_process on;\r\n \u00e2\u00e228422 nginx: worker process\r\n \u00e2\u00e228423 nginx: worker process\r\n\r\nJul 24 02:40:17 hostname systemd[1]: Starting A high performance web server and a reverse proxy server...\r\nJul 24 02:40:17 hostname systemd[1]: Started A high performance web server and a reverse proxy server.\r\n<\/pre>\nEnable Nginx to automatically start after a server reboot<\/p>\n
systemctl enable nginx<\/pre>\n<\/span>Step 3: Install Certbot<\/strong><\/span><\/h2>\nCertbot is a free and open-source tool written in Python which helps to obtain the SSL certificate from Let’s Encrypt and configure it onto your web server. The version of Cerbot that can be installed from the official Ubuntu repositories is outdated, so in order to install the latest version maintained by the Certbot team, we will have to add the Certbot PPA to your list of repositories.<\/p>\n
To do that, run to following commands on your server<\/p>\n
apt install software-properties-common\r\nadd-apt-repository universe\r\nadd-apt-repository ppa:certbot\/certbot<\/pre>\nDuring the process of adding the repository, you will be prompted to hit the Enter button to accept it. After that update the repositories list<\/p>\n
apt update<\/pre>\nOnce the repository is added and the repositories list updated, go ahead and install the Certbot Nginx package<\/p>\n
apt -y install python-certbot-nginx<\/pre>\n<\/span>Step 4: Install a Let’s Encrypt SSL certificate<\/strong><\/span><\/h2>\nAs we mentioned in the ‘Prerequisites’ section of the tutorial, we will use domain.com<\/code> as an example domain. So, in order to obtain Let’s Encrypt SSL certificate for this domain name, we will run Certbot with the –nginx plugin which will edit the Nginx configuration for the specific domain.<\/p>\ncertbot --nginx -d domain.com<\/span> -d www.domain.com<\/span><\/pre>\nDuring the installation of the Let’s Encrypt SSL certificate, you will be prompted to enter an email address used for urgent renewal and security notices<\/p>\n
Enter email address (used for urgent renewal and security notices) (Enter 'c' to\r\ncancel): admin@domain.com<\/span><\/pre>\nRead and accept Let’s Encrypt’s Terms of Service<\/p>\n
Please read the Terms of Service at\r\nhttps:\/\/letsencrypt.org\/documents\/LE-SA-v1.2-November-15-2017.pdf. You must\r\nagree in order to register with the ACME server at\r\nhttps:\/\/acme-v01.api.letsencrypt.org\/directory\r\n-------------------------------------------------------------------------------\r\n(A)gree\/(C)ancel: A\r\n<\/pre>\nChoose whether or not you want to redirect all traffic to HTTPS, which is recommended.<\/p>\n
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.\r\n-------------------------------------------------------------------------------\r\n1: No redirect - Make no further changes to the webserver configuration.\r\n2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for\r\nnew sites, or if you're confident your site works on HTTPS. You can undo this\r\nchange by editing your web server's configuration.\r\n-------------------------------------------------------------------------------\r\nSelect the appropriate number [1-2] then [enter] (press 'c' to cancel): 2\r\n\r\nRedirecting all traffic on port 80 to ssl in \/etc\/nginx\/sites-enabled\/default\r\n-------------------------------------------------------------------------------\r\n<\/pre>\nWith this step, the SSL certificate for domain.com<\/code> is successfully installed and you can access your domain name at https:\/\/domain.com<\/code>. You can use Certbot to verify this and check the certificate expiration date<\/p>\ncertbot certificates<\/pre>\nOutput:<\/p>\n
Saving debug log to \/var\/log\/letsencrypt\/letsencrypt.log\r\n-------------------------------------------------------------------------------\r\nFound the following certs:\r\n Certificate Name: domain.com\r\n Domains: domain.com\r\n Expiry Date: 2019-10-22 08:56:19+00:00 (VALID: 89 days)\r\n Certificate Path: \/etc\/letsencrypt\/live\/domain.com\/fullchain.pem\r\n Private Key Path: \/etc\/letsencrypt\/live\/domain.com\/privkey.pem\r\n-------------------------------------------------------------------------------<\/pre>\n