2

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

BenMorel
  • 4,507
  • 10
  • 57
  • 85
Daniel
  • 43
  • 1
  • 4
  • Why do you want run Varnish if you just want to pass everything through it instead of allowing it to cache it? – jdw Oct 04 '11 at 00: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 04 '11 at 01:01
  • @jdw devicenull is right, I'm using varnish for all static files, and passing every php request to apache – Daniel Oct 04 '11 at 14:34

4 Answers4

3

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.

Karel
  • 56
  • 3
0

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;
devicenull
  • 5,622
  • 1
  • 26
  • 31
  • 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 04 '11 at 15:06
0

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

Jan
  • 1
0

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

Geoffrey
  • 63
  • 2
  • 14