|
|
Apache Question
|
|
|
|
Posting Junkie
Join Date: Feb 2000
Location: Washington, DC
Status:
Offline
|
|
I work for a university and could use some advice from others that are in the know about Apache.
I'm looking to point a directory to a different server (Example: I want everything in http://www.mysite.com/blog/ to go to another server... but it should look seamless from the outside world)
I'm being told that it can't be done because we are already rerouting Apache and it may break Apache. They also indicated that if the other server went down, it could cause serious problems.
Thoughts?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
You need to think about this more at the DNS level than the Apache level. DNS entries can only either resolve to IP, or to several if you wish to setup a DNS round robin pool. You cannot have some requests to a certain directory in an HTTP request resolve to one IP, and another IP for other HTTP requests. DNS doesn't know anything about HTTP, Apache, or any other service you might want to serve via that domain. This is not an Apache problem or an Apache question, it's a DNS one.
Options for you:
- Redirect to a subdomain hosted on this other server
- Sync the data between the servers (several ways to do that)
- Fetch data from this server in real time (several ways to do this too)
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Couldn't you proxy to the other server?
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
If you are asking me, I don't know, I've never spent time with setting up proxies. I used Squid years ago though, but only for bandwidth throttling. Whether you could proxy only for certain directories is another unknown. I think as far as the original poster is concerned, there are probably easier solutions (such as the subdomain).
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Jul 2005
Location: Vacation.
Status:
Offline
|
|
IIRC, Squid will do it (reverse proxy setup, obviously). But I agree with Bess on the subdomain thing.
|
Been inclined to wander... off the beaten track.
That's where there's thunder... and the wind shouts back.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Yeah, a subdomain would be way easier, but I'm pretty sure you can accomplish what Mitchell's looking for (though my Apache-fu is quite rusty and I couldn't tell you exactly how to do it offhand).
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Setting up Squid would require root access to the server too, I'm sure.
I'd suggest learning and exploring as much as you can before diving in to this. If there is anything fuzzy you should clear that up for your own benefit, as well as to explore easier options. Using a proxy like this, AFAIK, would be a pretty strange and conventional way to go about solving this that I'd probably consider a last resort. Squid is not going to be easy if you are new to all of this.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Another option, a very ugly and lazy man's option but one that would work in a pinch: an iframe.
|
|
|
|
|
|
|
|
|
Posting Junkie
Join Date: Oct 2005
Location: Houston, TX
Status:
Offline
|
|
Why not just use an HTTP 301/302 as appropriate?
Or mod_rewrite if you want to preserve the URL.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
The only way you can use mod_rewrite to change a URL from one server to a URL from another is with a redirect — so basically your option 1 is the only choice.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by mduell
Why not just use an HTTP 301/302 as appropriate?
Or mod_rewrite if you want to preserve the URL.
He would need a URL to redirect to, and mod_rewrite does not rewrite external URLs, only local paths.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
Use mod_rewrite
If not, do what I do using PHP
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by hyteckit
Use mod_rewrite
No go for external URLs, as has been said
If not, do what I do using PHP
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
This is just a screen scraper, you don't get the Javascript DOM manipulation execution, Javascript event handlers, etc. Images that aren't referenced within an absolute URL including the domain will be broken, and all external CSS rules do not come along for the ride.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
Originally Posted by besson3c
No go for external URLs, as has been said
This is just a screen scraper, you don't get the Javascript DOM manipulation execution, Javascript event handlers, etc. Images that aren't referenced within an absolute URL including the domain will be broken, and all external CSS rules do not come along for the ride.
Not true.
I have 1 php application/website running multiple domains.
Just need to use mod_rewrite and redirect all paths to the main php script.
If the javascript, css, and images are relative paths, they should work fine just by setting the:
<base href="http:www.newsite.com">
If the links are absolution paths, you'll need to do a global replace of the old url with the new url.
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Could you show us the rewrite rules? I'd like to see them, if I'm wrong this would be handy to learn.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
.htaccess
----------
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/blog/ [NC]
RewriteRule ^blog/(.*)$ blog.php?$1 [L]
Every request that contains the URI ^/blog/ would get redirected to the script blog.php.
blog.php would be the script that contains:
<?php
$query_string = explode('/',$_SERVER["REQUEST_URI"]);
#Do what you need to do with $_SERVER["REQUEST_URI"]
$homepage = file_get_contents('http://www.example.com/'); # or whatever url that was requested
#replace the base href with the new url. replace the absolute paths with the new url
echo $homepage;
?>
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Okay, but what about all of the other files that www.example.com depends on? How are these local requests mapped to the external domain so that all of the external Javascript, CSS, image, etc. files work?
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
Originally Posted by besson3c
Okay, but what about all of the other files that www.example.com depends on? How are these local requests mapped to the external domain so that all of the external Javascript, CSS, image, etc. files work?
It does. Just do this:
<?php
$homepage = file_get_contents('http://www.newsite.com/'.$_SERVER["REQUEST_URI"]);
#replace the base href with the new url. replace the absolute paths with the new url
echo $homepage;
?>
I do this with microsoft's website and drop an image of some poop on top of it.
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
#replace the base href with the new url. replace the absolute paths with the new url
I was asking about how you do this, thinking that you wouldn't have to update the base hrefs in your application and HTML output... I guess you do though.
If that application would ever be relocated to a different domain again, I suppose you could generalize this by creating a dummy domain, putting this entry into your /etc/hosts, and just calling this domain from your app:
src="http://dummydomain.com/path/to/file"
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
Originally Posted by besson3c
I was asking about how you do this, thinking that you wouldn't have to update the base hrefs in your application and HTML output... I guess you do though.
If that application would ever be relocated to a different domain again, I suppose you could generalize this by creating a dummy domain, putting this entry into your /etc/hosts, and just calling this domain from your app:
src="http://dummydomain.com/path/to/file"
Not sure what you mean.
Say you move your whole 'blog' site from http://www.oldsite.com/blog to a new website http://www.newsite.com/blog/.
Say if your images still contain the oldsite url:
<img src="http://www.oldsite.com/blog/sexyimage.jpg">
You would want to replace the url www.oldsite.com with www.newsite.com.
In your blog.php script:
$homepage = file_get_contents('http://www.newsite.com/'.$_SERVER["REQUEST_URI"]);
$homepage = preg_replace('/oldsite\.com/gi','newsite.com',$homepage);
echo $homepage;
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
I guess you script is now a proxy script.
It handles all the request.
Processes the request and fetches the data from the desire location.
Parse out the data and rewriting all its paths.
Then prints out the data.
If you are geeky enough, you can cache the results according to the requested URL, so you don't have to keep fetching from the new site. Even if the new site is down, you'll have a cache version.
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Originally Posted by hyteckit
Not sure what you mean.
Say you move your whole 'blog' site from http://www.oldsite.com/blog to a new website http://www.newsite.com/blog/.
Say if your images still contain the oldsite url:
<img src="http://www.oldsite.com/blog/sexyimage.jpg">
You would want to replace the url www.oldsite.com with www.newsite.com.
In your blog.php script:
$homepage = file_get_contents('http://www.newsite.com/'.$_SERVER["REQUEST_URI"]);
$homepage = preg_replace('/oldsite\.com/gi','newsite.com',$homepage);
echo $homepage;
What about paths in external CSS files or Javascript files? You'd have to open these and parse them, and somehow create a local copy of these or something. What about paths that don't have a domain attached to them? You'd have to detect absolute and relative paths and manipulate these to become the proper absolute URL.
This is an interesting hack, but it would require a fair amount of parsing and manipulation of the pages it pulls in in order to work properly. I suppose it's a good last resort sort of technique, but I would say that this should only be an attractive option if you are fairly desperate to make this sort of thing work.
Of course, maybe it works beautifully for you if you do not use CSS background images referenced in an external file and stuff like that, or you don't mind reattaching these via a Javascript trigger on load or something like that.
|
|
|
|
|
|
|
|
|
Addicted to MacNN
Join Date: May 2001
Status:
Offline
|
|
Originally Posted by besson3c
What about paths in external CSS files or Javascript files? You'd have to open these and parse them, and somehow create a local copy of these or something. What about paths that don't have a domain attached to them? You'd have to detect absolute and relative paths and manipulate these to become the proper absolute URL.
This is an interesting hack, but it would require a fair amount of parsing and manipulation of the pages it pulls in in order to work properly. I suppose it's a good last resort sort of technique, but I would say that this should only be an attractive option if you are fairly desperate to make this sort of thing work.
Of course, maybe it works beautifully for you if you do not use CSS background images referenced in an external file and stuff like that, or you don't mind reattaching these via a Javascript trigger on load or something like that.
If it's too much trouble then just use mod_rewrite for all the CSS, JS, and images. No one is really going to check where the CSS, JS, and images come from.
So just use mod_rewrite for all the JS, CSS, and images instead of using the PHP for rewrite.
.htaccess
----------
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/blog/ [NC]
RewriteRule ^blog/(.*)\.(css|js|ico|jpg|jpeg|png|gif|ico)$ http://www.newsite.com/blog/$1.$2 [L]
RewriteRule ^blog/(.*)$ blog.php?$1 [L]
|
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
Interesting. For some reason I thought that external rewriting wasn't permitted, but I see that it is here given this example:
From this page
I can see how all of this put together would work beautifully, the above being a key ingredient.
Rewriting is extremely useful, I actually use it all the time. It's reason enough to learn regex, but just when you think you know it all you learn something new. Cool
Thanks for bearing with me, hyteckit.
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Mar 2001
Location: yes
Status:
Offline
|
|
hyteckit: it looks like you should include an "[R=301]" or "[R]" flag at the end of the external redirection line, no?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|