Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

up vote 3 down vote accepted

Change your setup like this:

  • apache runs on 127.0.0.1, port 80
  • varnish runs on 192.168.1.1 port 80 (where 192.168.1.1 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:

$_SERVER['SERVER_PORT'] = 80;
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: http://php.net/manual/en/ini.core.php )

But again this is not a clean solution ;-)

share|improve this answer

I have added support for this in the newer mod_rpaf @ https://github.com/gnif/mod_rpaf.

share|improve this answer

Your Answer

 
discard

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.