Create a custom folder and then copy the file:
|
1 |
cp -p /usr/local/directadmin/data/templates/openlitespeed_vhost.conf /usr/local/directadmin/data/templates/custom/ |
Edit it:
|
1 |
nano /usr/local/directadmin/data/templates/custom/openlitespeed_vhost.conf |
Between |CONTEXTS| and |REALMS|, insert |CUSTOM3| and save.
|
1 2 3 |
|CONTEXTS| |CUSTOM3| |REALMS| |
Before writing the headers, make sure it belongs to the user diradmin:
|
1 2 3 |
cd /usr/local/directadmin/data/templates/custom/ touch openlitespeed_vhost.conf.CUSTOM.3.pre chown diradmin:diradmin openlitespeed_vhost.conf.CUSTOM.3.pre |
Edit the file:
|
1 |
nano openlitespeed_vhost.conf.CUSTOM.3.pre |
and add the following:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders Strict-Transport-Security: max-age=31536000; includeSubDomains; preload } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders X-Content-Type-Options nosniff } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders X-XSS-Protection 1;mode=block } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders X-Frame-Options SAMEORIGIN } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders Referrer-Policy strict-origin-when-cross-origin } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders Permissions-Policy geolocation=(), microphone=(), camera=() } context / { location $DOC_ROOT/ allowBrowse 1 extraHeaders Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval'; frame-ancestors 'self';" } |
After adding the required headers, you must regenerate the domain configurations and restart OpenLiteSpeed:
|
1 2 3 |
cd /usr/local/directadmin/custombuild ./build rewrite_confs systemctl restart lsws |
Finally, it’s a good idea to hide the PHP version by editing the corresponding php.ini file:
|
1 |
expose_php = Off |
You can check if your score has improved on the website securityheaders.com.
Source:
https://www.vpsbasics.com/cp/how-to-add-http-security-headers-with-openlitespeed-and-directadmin
