I didn't explicitly specify them(X headers), I found them defined.
Does Plesk have a setting method unique to Plesk?
With "nginx -T | less" you can search for "X-" and find out where certain directives are configured.
You can place site's directives in the section "Apache and Nginx settings".
I have no idea if you want to set directives for 1 site or for all.
I prefer to have a central place to place directives server-wide. To achieve this I wrote a cronjob script that will place a vhost_nginx.conf in /var/www/vhosts/system/*/conf/ in each directory where there is none.
This file will only contain an include of /var/www/vhosts/system/conf/vhost_nginx.conf
In that file I will put my server-wide settings.
Each domain will get a vhost_nginx.conf after the subscription is created.
It will have this content:
cat /var/www/vhosts/system/client.com/conf/vhost_nginx.conf
Code:
include /var/www/vhosts/system/conf/vhost_nginx.conf;
You can still add custom commands using the Plesk interface or even remove the "include entry".
If you only need to do this for 1 or 2 sites, I would just enter them in "Apache & nginx Settings"
cat /var/www/vhosts/system/conf/vhost_nginx.conf
Code:
add_header Referrer-Policy strict-origin-when-cross-origin;
add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options nosniff;
The script is comprehensive because it does a lot of checks and has the ability to revert its actions.
Because it runs each hour in the background this is necessary.
I would only use this scipt if you are a hosting provider that adds and removes clients on a regular basis.
If you don't I would just run it on the command-line or use the "Apache & nginx Settings".
In practice it will only execute on newly created subscriptions as they start without any vhost_nginx.conf file.
The "plesk repair web ${DOMAIN}" it executes has therefore no ill-effect on the other sites,
ln -s /usr/local/sbin/vhost_nginx /etc/cron.hourly/
cat /usr/local/sbin/vhost_nginx
Code:
#!/bin/bash
INCLUDE=/var/www/vhosts/system/conf/vhost_nginx.conf
HEADLESS=
tty >/dev/null || HEADLESS=true
THISSCRIPT="`readlink -f $0`"
SCRIPTNAME=${THISSCRIPT##*/}
[ -z "${SCRIPTNAME}" ] && SCRIPTNAME=${0##*/}
LOG=/var/log/${SCRIPTNAME}.log
PLESKBIN=/usr/local/psa/bin/domain
if [ ! -f ${INCLUDE} ] ; then
echo "There is no file ${INCLUDE}" >&2
exit 1
fi
if ! nginx -t 2>/dev/null ; then
echo "The Nginx configuration is not valid, abort" >&2
exit 1
fi
TMPDIR=`mktemp -t -d ${0//*\/}.XXXXXXXXXX`
CREATED=
TMPLOG=${TMPDIR}/log
echo "`date` **** Found new domain(s) to add a new vhost_nginx.conf" >${TMPLOG}
find /var/www/vhosts/system/ -mindepth 2 -maxdepth 2 -type d -name conf >${TMPDIR}/confs
while read CONF ; do
NGINXCONF=${CONF}/vhost_nginx.conf
if [ ! -e ${NGINXCONF} ] ; then
CREATED=true
DOMAIN="`echo ${CONF} | sed 's/.*system\///g;s/\/.*//g'`" # extract DOMAIN out of folder name
echo "Create ${NGINXCONF}" | tee -a ${TMPLOG}
# create a vhost_nginx.conf in the conf of the domain system space
echo "#######################################################################" >${NGINXCONF}
echo "# server-wide directives are included from the file ${INCLUDE}" >>${NGINXCONF}
echo "# This file is maintained by your provider and can NOT be edited by you" >>${NGINXCONF}
echo "# You can of course edit the content here upon your liking" >>${NGINXCONF}
echo "#######################################################################" >>${NGINXCONF}
echo "# Upon creation of the domain this file (${INCLUDE}) contained:" >>${NGINXCONF}
echo "# " >>${NGINXCONF}
sed 's/.*/# &/g' ${INCLUDE} >>${NGINXCONF}
echo -e "\ninclude ${INCLUDE};\n" >>${NGINXCONF}
# Modify permissions of this new file
chmod 600 ${NGINXCONF}
chown root:nginx ${NGINXCONF}
# Although the file is created it is not added in the nginx config, I will use "plesk repair" for this
plesk repair web ${DOMAIN} -y -v
if ! nginx -t 2>/dev/null ; then # check if the nginx config is still valid
echo "Somehow the Nginx config became invalid after adding this include to ${INCLUDE}" | tee -a ${TMPLOG} >&2
echo "I will remove the file I just created (${NGINXCONF})" | tee -a ${TMPLOG} >&2
rm ${NGINXCONF} # remove the vhost_nginx.conf of this domain
plesk repair web ${DOMAIN} -y -v # let plesk repair fix this (tested this)
if ! nginx -t 2>/dev/null ; then # check the nginx config AGAIN to make sure it got fixed
nginx -t 2>&1 | tee -a ${TMPLOG} >&2
echo "plesk repair did not fix this" | tee -a ${TMPLOG} >&2
echo "We now have an invalid nginx config, I will abort the script" | tee -a ${TMPLOG} >&2
break
fi
fi
fi
done<${TMPDIR}/confs
echo "`date` **** Finished adding vhost_nginx.conf" >>${TMPLOG}
[ ${CREATED} ] && cat ${TMPLOG} >>${LOG}
rm -r ${TMPDIR}