Azure hosting LEMP with PHP 7.1 and Laravel 5.4 — Part 3

CONVENTIONS

Bold text shows commands as they should be entered literally by the reader at the command prompt.

AZURE

To allow access to HTTPS, we first have to make port 443 (HTTPS) accessible from the Azure virtual machine host.

HTTPS

az vm open-port --port 443 --priority 800 --resource-group {UNIQUE_RESOURCE-GROUP_NAME} --name {UNIQUE_VIRTUAL-MACHINE_NAME}

SSL

We now have to register for a certificate, authenticate and install them, and finally configure and restart Nginx. Luckily for us, this can be all automated and free because of the excellent Certbot client and LetsEncrypt certificates.

CertBot
install_ssl.sh
  • --email To pass on recovery email.
  • --agree-tos To agree to the Terms of Service.
  • --no-eff-email To not join the EFF mailing list.
  • --non-interactive Run without asking for user input.
  • --redirect Redirect the request to HTTPS from the web server.
ssl_dhparam /etc/ssl/certs/dhparam.pem;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/{UNIQUE_VIRTUAL-MACHINE_NAME}.eastus.cloudapp.azure.com/fullchain.pem; # managed by Certbotssl_certificate_key /etc/letsencrypt/live/{UNIQUE_VIRTUAL-MACHINE_NAME}.eastus.cloudapp.azure.com/privkey.pem; # managed by Certbotinclude /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot

Conclusion

In this article we have completed securing an installation of a Nginx web server using CertBot and LetsEncrypt certificates. Users can now access the example Laravel application through HTTPS and will be redirected if they try to access it using the HTTP protocol. This concludes the article series, feel free to use the mentioned scripts and modify to your desire to help automate your workflow.

--

--

Daydreaming night owl, giver of unsolicited advice, software engineer by passion, always learning and ever living...

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Robert Brisita

Robert Brisita

Daydreaming night owl, giver of unsolicited advice, software engineer by passion, always learning and ever living...