You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once on https://certbot.eff.org/, I will identify that my HTTP website is running Nginx on Ubuntu 20. Filling this will provide me several commands that I need to run to get a free SSL certificate. To use certbot, I will need these things:
43
+
Once on https://certbot.eff.org/, I will identify that my HTTP website is running `Nginx` on `Ubuntu 20`. Filling this will provide me several commands that I need to run to get a free SSL certificate. To use certbot, I will need these things:
44
44
45
45
- Comfort with the command line interface
46
46
- A HTTP website what is already online with an open port (80)
47
47
- Application hosted on a server that can be accessed via SSH with the ability to run sudo commands
48
48
49
+
50
+
## Certbot Commands
51
+
52
+
These are the commands I need to get a free SSL certificate:
To understand what each command does, I have provided brief descriptions below.
63
+
64
+
1. To run the Certbot commands, I will need to SSH into my server:
65
+
66
+
```python
67
+
$ ssh gitauharrison@212.71.247.241
68
+
```
69
+
70
+
Ubuntu 20.04 comes with`snapd` pre-installed, so I do not have to worry about this. If your machine does not have it, make sure you install it. You can check [Conanical documentation](https://snapcraft.io/docs/installing-snapd) to find out how you can work with`snapd`.
71
+
<br>
72
+
73
+
74
+
2. Once I am in the server, I will need to update my version of `snapd` to the latest version:
3. Next, I need to remove anyOS package manager like `apt` before installing `certbot`. This is to ensure that when I run the command `certbot`, the snap is used andnot the OS package manager.
Now, I am ready to run the command `certbot`. But before I do that, I need to make some changes to my Nginx configuration. I will open the Nginx configuration filein the nano editor:
I will be asked a few questions such as what my email address is, if I would like to share my email with the foundation and to select a name I would like to activate HTTPSfor. Everything should work fine and a certificate successfully delivered and received. Reading the messages carefully in my terminal, I realized that the certificate is to be deployed for www.bolderlearner.com to `/etc/nginx/sites-enabled/somasoma_elearning`.
129
+
130
+
I will open this filein`nano` to see these changes:
True to there word, my Nginx configuratin file has been automatically updated.
138
+
139
+
140
+
`/etc/nginx/sites-enabled/somasoma_elearning`: Changes made by certbot
141
+
142
+
```python
143
+
server {
144
+
server_name www.bolderlearner.com;
145
+
location /static {
146
+
alias /home/gitauharrison/somasoma_elearning_app/app/static;
147
+
}
148
+
location / {
149
+
proxy_pass http://localhost:8000;
150
+
include /etc/nginx/proxy_params;
151
+
proxy_redirect off;
152
+
}
153
+
154
+
155
+
listen 443 ssl; # managed by Certbot
156
+
ssl_certificate /etc/letsencrypt/live/www.bolderlearner.com/fullchain.pem; # managed by Certbot
157
+
ssl_certificate_key /etc/letsencrypt/live/www.bolderlearner.com/privkey.pem; # managed by Certbot
158
+
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
159
+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
160
+
161
+
}
162
+
server {
163
+
if ($host = www.bolderlearner.com) {
164
+
return301 https://$host$request_uri;
165
+
} # managed by Certbot
166
+
167
+
168
+
169
+
listen 80;
170
+
server_name www.bolderlearner.com;
171
+
return404; # managed by Certbot
172
+
173
+
174
+
}
175
+
```
176
+
177
+
I said that I wanted the HTTP traffic to be redirected to HTTPS. The second `server` block captures this directive. If the host is www.bolderlearner.com, then all redirects (denoted by 301) will be through HTTPS.
178
+
179
+
180
+
### Testing NGinx Configuration
181
+
182
+
183
+
To test my Nginx configuration, I will run the command `nginx -t` in the terminal:
2022/02/1005:36:26 [warn] 105538#105538: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: configuration file/etc/nginx/nginx.conf test failed
196
+
```
197
+
198
+
It seems like I have an error, but the "error" in question is actually a permission issue. To fix this, I need to prefix the command above with `sudo`.
199
+
200
+
201
+
```python
202
+
gitauharrison@bolderlearner:~$ sudo nginx -t
203
+
204
+
205
+
# Output
206
+
207
+
nginx: the configuration file/etc/nginx/nginx.conf syntax is ok
208
+
nginx: configuration file/etc/nginx/nginx.conf test is successful
209
+
```
210
+
211
+
Originally, when setting up my firewall, I allowed HTTP traffic. I need to update this to allow HTTPS traffic. On the terminal, I will run:
I can optionally disallow HTTP traffic, but I will not do that because my configuration is already set to redirect all HTTP traffic to HTTPS. Before I can test my website to see if all these changes have taken effect, I will restart my Nginx server:
This certificate typically lasts for around 90 days and after that I need to renew it. This can be really cumbersome, and I might even forget about it. I would want that just before the expiration date, the application is able to auto-renew this certificate for me.
This is was a simulated renewal. To automate this renewal process, I will run a cronjob. I will open my crontab file using nano:
256
+
257
+
258
+
```python
259
+
gitauharrison@bolderlearner:~$ sudo crontab -e
260
+
261
+
262
+
# Output
263
+
264
+
no crontab for root - using an empty one
265
+
266
+
Select an editor. To change later, run 'select-editor'.
267
+
1. /bin/nano <---- easiest
268
+
2. /usr/bin/vim.basic
269
+
3. /usr/bin/vim.tiny
270
+
4. /bin/ed
271
+
272
+
Choose 1-4 [1]: 1# I have selected nano
273
+
```
274
+
275
+
Scroll to the bottom of the fileand add the following line:
276
+
277
+
`/tmp/crontab.SYULN5/crontab`: Auto-renewal
278
+
```python
279
+
3041** sudo certbot renw --quiet
280
+
```
281
+
To save, I will press `ctrl + X`, type`y`and hit `enter`. This basically autorenews the certificate at 4.30 am on the 1st of every month. The `--quiet` option tells the program to notprint out any messages or feedback.
0 commit comments