Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.