Take the 2-minute tour ×

I'm using haproxy 1.5-dev19 in front of Apache 2.4 (on Ubuntu 12.04).

Haproxy is listening on ports 80 and 443, and Apache is listening on 8080 — yet, when I output $_SERVER['SERVER_PORT'] from PHP (5.5), it shows as 80, when it should be 8080.

That is, I would assume PHP sees the Apache server port, but that doesn't seem to be the case.

What could I be overlooking?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Setting UseCanonicalPhysicalPort On and UseCanonicalName On in the Apache configuration file will cause PHP to report the correct server port.

It's possible haproxy "spoofs" its forwarded requests so that PHP sees the requests as port 80 instead of 8080.

share|improve this answer
Thanks, I'm testing these changes right now. Extra question: if I set UseCanonicalName = On, will PHP's $_SERVER['HTTP_HOST'] always be set to the ServerName that's configured? –  Joel L Aug 12 '13 at 12:31
Also, your answer states that these are php.ini settings — they're actually Apache config settings. –  Joel L Aug 12 '13 at 12:32
I made some edits to your answer based on my testing. –  Joel L Aug 12 '13 at 13:17
Whoops, nice catch. :) –  Nathan C Aug 12 '13 at 13:25
add comment

Your Answer


