![]() |
HSTS enhances website security by forcing browsers to connect only via HTTPS, preventing HTTP connections. This protects against hacking and spying. To enable HSTS in Apache, add the “Strict-Transport-Security” header to your configuration file. This instructs browsers to always use a secure connection. Follow the steps carefully to implement HSTS and improve web security. HSTS Uses
Configuring HSTS in ApacheStep 1: Locate config fileThis important file tells Apache how to run your site. It may called the “httpd.conf”, “apache2.conf”, or “ssl.conf”. You can usually find it in the “/etc/apache2” or in the “/etc/httpd” folder. Step 2: Turn on headersHSTS is sent as a special header instruction. To use headers, you need to turn them on first. On some systems, you can do this by typing the below commands. Command: sudo a2enmod headers
sudo service apache2 restart
Output: ![]() Output Step 3: Add the HSTS headerOpen the config file in a text editor program by using the below command and Find the section for your website. Add this line of code inside that section. Add the below line of code in the configuration file. This line tells browsers to always use the secure HTTPS connection to your site and subdomains for one year. Code: Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Command: sudo gedit /etc/apache2/sites-enabled/000-default.conf
Output: ![]() Output Step 4: Restart ApacheAfter saving the change, you need to restart Apache for the new setting to work. Do this by typing the below command into the terminal. Command: service apache2 restart
Output: ![]() Output That’s it! You have now set up HSTS to make your Apache website more secure. Optimizing HSTS in Apache
Code: Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
Renew SSL on timeHSTS requires an SSL certificate to enable HTTPS. If your certificate expires, browsers may block your site until you get a new one. Test it works right: After setup, use online test tools to make sure HSTS is working properly on your site. These can catch any problems you need to fix. ConclusionIn conclusion setting up the HSTS is very important for making your Apache website secure. It forces browsers to only use the safe HTTPS connection, protecting your site and users’ information from bad people. Following this guide helps you enable HSTS properly. With HSTS on, your website becomes much more secure and safe for users to visit. FAQsWhat does HSTS do?
Why should I enable HSTS?
Is it hard to set up HSTS?
What happens if I disable HSTS later?
Can HSTS cause problems with my website?
|
Reffered: https://www.geeksforgeeks.org
Web Technologies |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |