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

how to force php to read SERVER_PORT as 80, when apache listens on 8080 and varnish listens on 80 ??

if my apache vhost is set to 8080, SERVER_PORT will always be 8080, this is troubling me a little since in many parts of the application some links are calculated with SERVER_NAME and SERVER_PORT together, .. so what I need is that php "believes" that SERVER_PORT is 80, so all links will pass trough varnish

share|improve this question
Why do you want run Varnish if you just want to pass everything through it instead of allowing it to cache it? – jdw Oct 4 '11 at 0:22
He could be using Varnish for static file caching, to prevent against the various Apache-specific attacks, or any number of reasons. – devicenull Oct 4 '11 at 1:01
@jdw devicenull is right, I'm using varnish for all static files, and passing every php request to apache – Daniel Oct 4 '11 at 14:34
up vote 3 down vote accepted

Change your setup like this:

  • apache runs on, port 80
  • varnish runs on port 80 (where is your actual real ip)

That way both daemons run on port 80. This ofcourse only works if you never need to reach apache from outside of the local machine.

share|improve this answer

I don't think there's any clean way to do this. Is there some file that's included by every PHP script that needs to be set this way? If so, you can do something awful like this:

share|improve this answer
thanks for the answer ,.. it looks like we will have to modify things on the code side , ... as you say there's no clean way to do it – Daniel Oct 4 '11 at 15:06

Well its not clean ... but on a huge codebase you might consider using "auto_prepend_file" via php.ini or .htaccess in which you could reset the $_SERVER variable. (See: )

But again this is not a clean solution ;-)

share|improve this answer

I have added support for this in the newer mod_rpaf @

share|improve this answer

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.