I personally don't like to change the port of the service itself.
I used iptables to redirect port 80 to port 8888
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8888
To make this flexible I modified my /etc/init.d/pound (the reverse proxy I'm using)
When pound starts it adds the rule and when it stops it deletes this rule.
POUND_PORT=`grep -A5 -im1 '^ListenHTTP' /etc/pound/pound.cfg | grep -i Port | awk '{print $2}' | tr -cd '0-9'`
ins_ipt_rule ()
{
iptables-save | grep PREROUTING | grep 'dport 80' | grep -q "${POUND_PORT}" || iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port ${POUND_PORT}
}
del_ipt_rule ()
{
iptables-save | grep PREROUTING | grep 'dport 80' | grep -q "${POUND_PORT}" && iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port ${POUND_PORT}
}
The reverse proxy is working after you also open port 8888 in your INPUT chain of the firewall.
I also don't like the very simple approach of the plesk module psa-firewall so I deleted it, but this is not necessary per se.
iptables-save >/etc/iptables.rules
aptitude remove psa-firewall
vi /etc/network/if-up.d/iptables
#!/bin/sh
iptables-restore </etc/iptables.rules
chmod +x /etc/network/if-up.d/iptables
Now we have to solve the problem that all logs contain the IP of the proxy instead of the accessing host.
mkdir -p /opt/psa/admin/conf/templates/custom/domain
cp /opt/psa/admin/conf/templates/default/server.php /opt/psa/admin/conf/templates/custom/
cp /opt/psa/admin/conf/templates/default/domain/domainVirtualHost.php /opt/psa/admin/conf/templates/custom/domain/
cp /opt/psa/admin/conf/templates/default/domain/subDomainVirtualHost.php /opt/psa/admin/conf/templates/custom/domain/
in those 3 files you need to replace the 'CustomLog' line with 2 'CustomLog' lines.
# diff /opt/psa/admin/conf/templates/default/domain/domainVirtualHost.php /opt/psa/admin/conf/templates/custom/domain/domainVirtualHost.php
28c28,29
< CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog
---
> CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog_proxy env=is-forwarder
> CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog env=!is-forwarder
# diff /opt/psa/admin/conf/templates/default/domain/subDomainVirtualHost.php /opt/psa/admin/conf/templates/custom/domain/subDomainVirtualHost.php
22c22,23
< CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog
---
> CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog env=!is-forwarder
> CustomLog <?php echo $VAR->domain->physicalHosting->logsDir ?>/<?php echo $OPT['ssl'] ? 'access_ssl_log' : 'access_log' ?> plesklog_proxy env=is-forwarder
# diff /opt/psa/admin/conf/templates/default/server.php /opt/psa/admin/conf/templates/custom/server.php
16a17
> SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" is-forwarder
18a20
> LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" plesklog_proxy
21a24
> LogFormat "<?php echo $VAR->server->webserver->apache->pipelogEnabled ? '%v@@%p@@' : ''?>%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" plesklog_proxy
25c28,29
< CustomLog "|<?php echo $VAR->server->productRootDir ?>/admin/sbin/pipelog <?php echo $VAR->server->webserver->httpsPort ?>" plesklog
---
> CustomLog "|<?php echo $VAR->server->productRootDir ?>/admin/sbin/pipelog <?php echo $VAR->server->webserver->httpsPort ?>" plesklog env=!is-forwarder
> CustomLog "|<?php echo $VAR->server->productRootDir ?>/admin/sbin/pipelog <?php echo $VAR->server->webserver->httpsPort ?>" plesklog_proxy env=is-forwarder
Then issue the commands:
/opt/psa/admin/sbin/httpdmng --reconfigure-all
/etc/init.d/apache2 restart
This will change all the configs of the domains on your Plesk
When Apache detects an X-Forwarded-For field it will use '%{X-Forwarded-For}i' instead of '%h'
When the proxy is turned off there's a potential risk that a foreign proxy will influence your log too.
I could set the 'is-forwarder' with the 'hostaddress' being the local proxy IP, but I don't know (yet) how to do this.
If your proxy is always turned on this is a non-issue.
I used this as a reference:
http://80.84.224.198/plesk/Plesk/PP...nistration-guide/index.htm?fileName=68693.htm