How To: Optimizing SSL on Laravel Forge

Published on by

How To: Optimizing SSL on Laravel Forge image

Let’s Encrypt is a new automated SSL certificate authority. Because it is free, it is opening the doors to an exciting new era of secure servers and technologies. Laravel Forge was recently to allow one-click installations of Let’s Encrypt certificates. It is now easier than ever to have your own SSL!

Let’s take a few extra minutes to optimize your server and help it perform faster and be more secure. In this tutorial we will look at using SSL session caching, HTTP Strict Transport Security (HSTS), and Hypertext Transfer Protocol 2 (HTTP/2).

Prerequisites

  • A forge-managed server.
  • Site running under SSL.
  • nginx 1.9.5 or higher for HTTP/2 (everything else should work).

Considerations

Multiple HTTPS sites on a single IP address will cause nginx to use SNI to establish an SSL connection. Internet Explorer 8 and below on Windows XP, as well as Android 2.3.7, do not support SNI. They will likely report a broken certificate, or might not be able to connect at all. This is only something to worry about if you need to support old browsers.

SSL Log-Jam Fix

Forge now includes a recipe to apply the Diffie-Helmann Log-Jam Vulnerability patch. Run that against the server in question before performing the following steps.

SSL Optimizations

Enabling SSL can slow down your site’s load times, especially if you have many files. Each request has some overhead of SSL negotiation. before a response gets issued. Setting up SSL session caching eliminates renegotiation for each request unless the cache expires.

Using an optimized cypher suite will further harden our security configuration. This will address browser compatibility and cypher blacklists.

We will also enable Online Certificate Status Protocol (OCSP) stapling. The server will cache the revocation status of the SSL certificates. This eliminates the need to query the certificate authority each time.

All these settings are best set up as a recipe in Laravel Forge. You can then run it with ease against any of your servers:

Here is the script depicted above:

> **Note:** adding this recipe to a server will not affect the non-SSL-secured web sites on your server.

HTTP Strict Transport Security (HSTS)

HSTS is a web security policy mechanism which helps to protect websites against protocol downgrade attacks and cookie hijacking. It allows web servers to declare that web browsers (or other complying user agents) should only interact with it using secure HTTPS connections,[1] and never via the insecure HTTP protocol. – Wikipedia

Enabling HSTS gives us all the benefits for browsers that support it. It also won’t affect browsers that don’t support it.

Lets get to it. For this we need to edit your sites nginx configuration file. You can get to it using the Edit Files drop-down on your site screen in Laravel Forge:

Add the following line to your server block:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

Note: some tutorials include a trailing “always” keyword. But that isn’t the correct usage of the command in this case. It should not be in every response. Instead, the browser will determine the correct usage of the HSTS header once it sees it.

HTTP/2

This is by far the simplest step. In your site’s nginx configuration file add “http2” to the end of the listen line for the server block.

listen 443 ssl http2;

Note: Do not add this to the non-ssl server block listening on port 80.

Wrapping Things Up

All that’s left now is to reload nginx and test your server’s SSL configuration.

Next head to SSL Labs and test your certificate. You should now be sporting a solid “A+”! Congratulations on making the internet a faster and safer place! If you go to your site now, you should notice an appreciable speed increase compared to before.

Mike Bronner photo

Husband. Genealogist. Web Designer. Translator. German-American.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.

Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $2500/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Rector logo

Rector

Your partner for seamless Laravel upgrades, cutting costs, and accelerating innovation for successful companies

Rector
MongoDB logo

MongoDB

Enhance your PHP applications with the powerful integration of MongoDB and Laravel, empowering developers to build applications with ease and efficiency. Support transactional, search, analytics and mobile use cases while using the familiar Eloquent APIs. Discover how MongoDB's flexible, modern database can transform your Laravel applications.

MongoDB

The latest

View all →
Asymmetric Property Visibility in PHP 8.4 image

Asymmetric Property Visibility in PHP 8.4

Read article
Access Laravel Pulse Data as a JSON API image

Access Laravel Pulse Data as a JSON API

Read article
Laravel Forge adds Statamic Integration image

Laravel Forge adds Statamic Integration

Read article
Transform Data into Type-safe DTOs with this PHP Package image

Transform Data into Type-safe DTOs with this PHP Package

Read article
PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell image

PHPxWorld - The resurgence of PHP meet-ups with Chris Morrell

Read article
Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3 image

Herd Executable Support and Pest 3 Mutation Testing in PhpStorm 2024.3

Read article