Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing port 80 with mod_rewrite 2

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Apache novice so please be gentle. [smile]

Would like to effectively 'share' port 80 between 2 servers on a LAN.

Windows server 1 is running WAMP and port 80 is forwarded to server 1

In \path\httpd-vhosts.conf there is
Code:
<VirtualHost *:80>
	ServerName [URL unfurl="true"]www.mysite.net[/URL]
	ServerAlias mysite.net mysite
    DocumentRoot C:/wamp/[URL unfurl="true"]www/mysite[/URL]
    ErrorLog C:/wamp/[URL unfurl="true"]www/mysite/logs/error.log[/URL]
    CustomLog C:/wamp/[URL unfurl="true"]www/mysite/logs/access.log[/URL] common
</VirtualHost>

<VirtualHost *:80>
	ServerName [URL unfurl="true"]www.yoursite.com[/URL]
	ServerAlias yoursite.com yoursite
    DocumentRoot C:/wamp/[URL unfurl="true"]www/yoursite[/URL]
    ErrorLog C:/wamp/[URL unfurl="true"]www/yoursite/logs/error.log[/URL]
    CustomLog C:/wamp/[URL unfurl="true"]www/yoursite/logs/access.log[/URL] common
</VirtualHost>
and all works correctly.

Would like to use mod_rewrite to redirect 'yoursite.com' to another WinXP Pro box, this time running IIS, to C:\Inetpub\
If possible, ideas please?

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Just "yoursite.com"? Sure:

RewriteEngine on
RewriteCond %{HTTP_HOST} yoursite.com
RewriteRule ^(.*)$ [R]

But remember, this will only work internally (because 192.168 is unroutable).
 
This is a redirect. Once this server sees:
it will redirect the browser to

This server is no longer in the loop, the browser is only interacting with the server at 192.168.0.n

That is why this can only work internally, it can't be used to access 192.168.0.n from the internet.
 
Have tried the suggested code without the DocumentRoot reference in the \path\httpd-vhosts.conf as originally posted.

The Apache server restarts correctly but the redirect is to the WAMP5 homepage on the first server.

What's missing, please?

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Are you trying it outside your network? As mentioned this will not work through a router because port 80 can only be forwaded to one internal IP address. I suspect that you're trying this across a router (because if you were'nt what would be the point of this exercise? - from inside the network, you could access the 2nd apache server directly without needing the redirect)
 
smah

Thanks for your reply.
smah said:
Are you trying it outside your network?
No


The purpose of the exercise is enable the hosting of domain 1 on an apache server and domain 2 on a Windows server running IIS.

Your comment
smah said:
As mentioned this will not work through a router because port 80 can only be forwaded to one internal IP address.
would indicate this is not possible.


I was hoping that it would be possible to effectively 'filter'the port 80 traffic as discussed earlier in the thread?

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
I wonder if the ServerName is screws up HTTP_HOST?

Try this, make another virtual host, almost identical to www:

<VirtualHost *:80>
ServerName yoursite.com
DocumentRoot C:/wamp/ ErrorLog C:/wamp/ CustomLog C:/wamp/ common

RewriteEngine on
RewriteRule ^(.*)$ [R]
</VirtualHost>

And take out the yoursite.com serveralias in
This says redirect EVERYTHING to that ip address.

Remember, once the redirect occurs it is up to the server at 192.168.0.n to do the right things.
 
Reran the suggested configuration with a clean apache error log and nothing shows in the error log.

Restored the previous configuration and the error log reports normal startup.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
I guess that my point is: why not access domain 2 on the windows server directly? I don't understand the requirement to access domain 2 on the apache server in the first place.
 
smah

smah said:
...because port 80 can only be forwarded to one internal IP address.
How would domain 1 then be accessed when port 80 has already been forwarded to domain 2?


The use of mod_aspdotnet or mono-project might be alternative solutions as well as the simplest and probably the best, the use of another web host for domain 1.
smah said:
I don't understand the requirement to access domain 2 on the apache server in the first place.
I have some projects in mind that might require the use of MS Visual Studio and thus IIS.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
external port 80 can only be forwarded to one internal IP address by a router[/b] which is what elgrandeperro also mentioned.
elgrandeperro said:
But remember, this will only work internally (because 192.168 is unroutable).

If your client machine is actually on the same network as the 2 web servers (with no NAT router in between) then why not access (on server1) when you need to use that and (on server2) when you need to use that one. No redirecting/rewriting is required if you access them directly. To access yahoo.com, do you go to msn.com then get redirected? No, you access yahoo.com directly. As long as both of those domains (and servers) are available from the network that you're on (the public internet for that example) you can access each directly. The same is true for your internal network

If your client machine is actually not on the same network (there's a NAT router in between and you're trying to access them from the public internet), then URL rewriting is not what you're looking for. In this case, you'd be trying to proxy one server through the other.
 
smah, elgrandeperro

Thanks you for your input, which has been both helpful and educational.

The matter has been resolved by an existing client offering free hosting of the WAMP server leaving port 80 unencumbered on the existing network. [smile]

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top