This is sometimes useful if we need to use a different SSL setup for subdomains when using Cloudflare as a DNS service provider. Cloudflare is not just limited to a DNS provider, it has got many features to improve the security and performance of websites.
Free SSL is one of the important features coming along with the Cloudflare free plan. Users can make use of this feature without installing any premium SSL certificate on the server. To use this feature we need to use Cloudflare as our DNS provider and need to switch DNS from the domain registrar. Follow this tutorial from Cloudflare to set up the Cloudflare for your domain.
When we navigate to the Cloudflare SSL page we can see the number of options as shown below to use SSL. But this setup will apply to all the subdomains and for the main domain under that website.
Set up Different SSL Option For Subdomain
Let's say I am using a Full(strict) SSL for the whole site, this means we need to have SSL installed for the whole domains and domains in the server. Sometimes this is not useful as we need to host subdomains in static file hosting sites like Aws s3 which does not support SSL certificates. In that case, we need to make use of flexible SSL for subdomains to avoid Cloudflare 502 bad gatway error or server accessible error.
Cloudflare provides a service called page rules which can be used to set up different page rules. We can use to apply a specific rule for the domain or pages in a website.
Flexible SSL for Subdomain
- Login to Cloudflare account
- Select the domain
- Navigate to Rules -> Page Rules -> Add new Rule
- Lets say we want to use flexible SSL for this subdomain static.example.com
- Add static.example.com/* in the input section, then select SSL from the drop down and just select Flexible
Now just select save and deploy.
Note: Flexible SSL does not encrypt communication between Cloudflare and our server as the communication between these is through the HTTP protocol.