Forum Moderators: phranque
My domain structure is as follows:
abc.com
abc.com/folder1
abc.com/folder2
abc.com/folder3
I have three web servers for sharing load. Currently all folders come from my main web server of course, as usual. But because of heavy site traffic I now want my "folder2" and "folder3" to come from different web servers.
Not domains or subdomains, but just *folders* of a site!
That's why I'm stuck. I was trying something like this in the httpd.conf for the main web server's Apache, so that I could forward (internally) all traffic from "/folder3" to the third web server--
RewriteCond %{HTTP_HOST} ^(www\.)?abc\.com\.?(:[0-9]+)?$
RewriteCond $1 folder3/
RewriteRule ^/(.*)$ http://10.10.x.3/folder3/$1 [L]
My couple questions:
1. In second line, how should I check for "folder3"? My code doesn't work.
2. In third line, how can I make sure an internal private IP redirect can be done without "R=301"? Including a [10.10.x.3...] requires an external redirect? If yes, then is there another way of leveraging a private LAN somehow to point *not* domains/subdomains but specific folders?
Many thanks!
Great RTFM there for me. But one concern: would ReverseProxy reduce performance? E.g., this somewhat dated mailing list post: [marc.info...]
Is there some kind of caching etc I could use?
would ReverseProxy reduce performance
Is there some kind of caching etc I could use?
Yes, mod_cache/mod_disk_cache for example. But I wouldn't proxy everything to a backend server, i.e., only dynamical generated content and serve static files as normal - may be with enablesendfile [httpd.apache.org] if OS permits - or use and reference a different server for resources such as images so that image requests won't hit your main server but e.g. img.example.com. That would require some HTML source code changes, of course.
I am forwarding the proxy from my main server something like this:
ProxyPass /folder http://server3.com/~domain/folder/
Now on the server3.com the value of PHP_SELF variable should be "/folder/x.php" but it is in fact "/~domain/folder/x.php".
I know it is the accurate value, but I want the paths to appear as they appear to the user in the browser.
Is there any Apache or PHP setting that will allow this?
ProxyPass /folder/ http://server3.com/~domain/folder/ Now on the server3.com the value of PHP_SELF variable should be "/folder/x.php" but it is in fact "/~domain/folder/x.php".
In order to communicate the frontend-requested uri to the backend server you'll have to set a request header via mod_headers
SetEnvIf Request_URI ^(/folder/.*) forw-uri=$1
RequestHeader set X-Forwarded-Uri %{forw-uri}e env=forw-uri
SetEnvIf Request_URI ^(/folder/.*) forw-uri=$1
RequestHeader set X-Forwarded-Uri %{forw-uri}e env=forw-uri
Then in the target (redirected) web server, from where the "folder" is read, I created a test PHP page (/folder/test.php).
<?php
echo $_SERVER['PHP_SELF'];
?>
But this still shows the "/~domain/folder/test.php". This should actually read "/folder/test.php".
Any thoughts?
$_SERVER['X-Forwarded-Uri'] if you use that header name in the RequestHeader directive (you can use any unless there is no conflict with existing ones).
did you mean I should replace the "forw-uri" with something of my own? I thought it's just a variable name.
That doesn't mean that you should set your application variables with headers or envs, but you could (SetEnv - not SetEnvIf - directive; avoid regular expressions). You'd have to use that directive at your backend server.
Is it better performance than using DEFINE in php because apache's env vars are available at runtime?