Crates.io | https_demo |
lib.rs | https_demo |
version | 0.1.2 |
source | src |
created_at | 2020-07-03 10:48:39.95662 |
updated_at | 2020-07-04 04:00:35.315984 |
description | https demo website in Rust |
homepage | https://github.com/mohankumaranna/https_demo |
repository | https://github.com/mohankumaranna/https_demo |
max_upload_size | |
id | 260963 |
size | 66,404 |
Demonstrates how to build https website(s) in Rust.
It took good amount of time to complete my first https website; hence, documenting those learnings!.
Hope, it may help others too!!.
Learned to use:
let ip_addr = CONFIG.ip_address.as_ref().unwrap();
let socket_addr: SocketAddr = ip_addr.as_str().parse().unwrap();
warp::serve(routes)
.run(socket_addr)
.await;
let ip_addr = CONFIG.ip_address.as_ref().unwrap();
let cert_path = CONFIG.cert_path.as_ref().unwrap();
let key_path = CONFIG.key_path.as_ref().unwrap();
let socket_addr: SocketAddr = ip_addr.as_str().parse().unwrap();
warp::serve(routes)
.tls()
.cert_path(cert_path)
.key_path(key_path)
.run(socket_addr)
.await;
For local testing, used a sample certificate found in warp framework example.
Ran the server in development machine.
Tested it in the browser with url: https://localhost:3010.
Ensured it was working.
On the hosting machine (DigitalOcean in my case),
a) ensured certbot was installed.
b) ensured port 80 or 443 were available; those ports were not in use by other programs such as web servers, nginx, or apache.
c) UFW (Uncomplicated Fire Wall) was disabled ( $ sudo ufw disable
).
d) iptable entries, that were used for port forwarding to few http websites, were deleted.
ran the following command successfully.
$ sudo certbot certonly --standalone -d example.com
tried again for multiple domains.
$ sudo certbot certonly --standalone -d example.com -d www.example.com OR $ sudo certbot certonly --standalone -d example.com,www.example.com
tried to add more domains after obtaining certificates.
$ sudo certbot certonly --expand -d example.com,www.example.com,new1.example.com,new2.example.com
It showed two options:
On success, it showed a `Congratulations!' message and place where certificates were stored.
Certificates were stored at /etc/letsencrypt/live/example.com/
.
Checked the added certificates using following command.
$ sudo certbot certificates
It showed certificate name, domains, certificate path, private key path.
For historical reasons, those certificate-containing-directories were created with permissions of 0700 meaning that certificates were accessible only to servers that ran as the root user.
Fixed this using command: $ sudo chmod 0755 /etc/letsencrypt/{live,archive}
.
It was also needed to use chgrp and chmod 0640 to allow the server to read /etc/letsencrypt/live/$domain/privkey.pem
. Please note, actual certificates and private keys were in archive folder; live folder contained only links to those files. Hence, applied chmod and chgrp command on archive folder.
$ sudo ufw status
)./etc/hosts
file with an entry of 127.0.0.1 example.com.$ sudo ufw allow 3010
)./etc/hosts
file with an entry of 127.0.0.1 example.com.$ sudo sysctl net.ipv4.conf.ens3.forwarding=1
$ sudo ifconfig
.$ sudo iptables -A PREROUTING -t nat -i ens3 -p tcp --dport 443 -j REDIRECT --to-ports 3010
$ sudo iptables -A FORWARD -t filter -p tcp -d 165.1.1.10 --dport 3010 -j ACCEPT
$ sudo iptables -t nat -L PREROUTING -n -v --line-numbers
$ sudo iptables -t filter -L FORWARD -n -v --line-numbers
$ sudo iptables -t nat -D PREROUTING <line-number-here>
for deleting a row in nat table$ sudo iptables -t filter -D FORWARD <line-number-here>
for deleting a row in filter tableDemo runs here.
MIT