Portents of Porting Ports
May 24, 2009 5:44 AM Subscribe
ApacheFilter: What's the easiest way to have a "default page" on an alternate port?
I've got Comcast cable internet at home, and I run a web server with several VirtualHosts.
Thinking about switching to FiOS, where port 80 is blocked.
The simple solution is to move my web content over to a different port -- in this case 81.
I've already set up the server to Listen on both ports. That's the easy part.
What I want to do is, before port 80 goes away, put a special note and redirect notice when people access any of my pages, at any of my domains, at port 80, without having 2 different versions of every domain.
What is the easiest way to accomplish this?
It is Apache 2.2.3 on Ubuntu where I have full root privileges.
I've got Comcast cable internet at home, and I run a web server with several VirtualHosts.
Thinking about switching to FiOS, where port 80 is blocked.
The simple solution is to move my web content over to a different port -- in this case 81.
I've already set up the server to Listen on both ports. That's the easy part.
What I want to do is, before port 80 goes away, put a special note and redirect notice when people access any of my pages, at any of my domains, at port 80, without having 2 different versions of every domain.
What is the easiest way to accomplish this?
It is Apache 2.2.3 on Ubuntu where I have full root privileges.
Response by poster: AzraelBrown, I thought it was "as simple as that", but it gave me a warning message from Apache about "using * and non-* ports with a NameVirtualHost directive".
By adding a NameVirtualHosts line with a specific reference to port 81, I've made the problem go away, and I think I'm good from here.
I also thought there might have been some RewriteRule nonsense I could have done instead; other answers still appreciated.
posted by jozxyqk at 8:00 AM on May 24, 2009
By adding a NameVirtualHosts line with a specific reference to port 81, I've made the problem go away, and I think I'm good from here.
I also thought there might have been some RewriteRule nonsense I could have done instead; other answers still appreciated.
posted by jozxyqk at 8:00 AM on May 24, 2009
The config AzraelBrown describes is definitely the simplest way, because you only need to make that one change in your config file, turning NameVirtualHost on for port 81 and off for all other ports. The only other thing you would need to do is add
UseCanonicalName off
to the config for the default (port 80) host. That will cause Apache to allow the client-specified HTTP_HOST header through, and you can use that in PHP or other server-side scripting to redirect to the appropriate site.
There are other ways to do it, although none as easy as that. If you want to use mod_rewrite, you could use the following in each vhost:
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* http://%{HTTP_HOST}:81/%{REQUEST_URI}?fromport80=true [QSA]
This says "If the client is using port 80, redirect them to port 81 and add to the query string the variable "fromport80=true". You could then add code to each site to check for fromport80 and warn them they'd better start using port 81.
posted by pocams at 8:56 AM on May 24, 2009
UseCanonicalName off
to the config for the default (port 80) host. That will cause Apache to allow the client-specified HTTP_HOST header through, and you can use that in PHP or other server-side scripting to redirect to the appropriate site.
There are other ways to do it, although none as easy as that. If you want to use mod_rewrite, you could use the following in each vhost:
RewriteEngine on
RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* http://%{HTTP_HOST}:81/%{REQUEST_URI}?fromport80=true [QSA]
This says "If the client is using port 80, redirect them to port 81 and add to the query string the variable "fromport80=true". You could then add code to each site to check for fromport80 and warn them they'd better start using port 81.
posted by pocams at 8:56 AM on May 24, 2009
Just always use * syntax and let it pick which vhost to use based on ServerName/ServerAlias. This is a lot easier than naming each virtual host.
etc..
posted by cj_ at 1:12 PM on May 24, 2009
NameVirtualHost *:80
NameVirtualHost *:81
<VirtualHost *:80>
DocumentRoot /path/to/message/docroot
</VirtualHost>
<VirtualHost *:81>
ServerName foo.com
...
</VirtualHost>
<VirtualHost *:81>
ServerName bar.org
...
</VirtualHost>
etc..
posted by cj_ at 1:12 PM on May 24, 2009
Response by poster: I just got an auto-notification that I should resolve this or set a "best answer"...
But it turns out that the question is moot for 2 reasons:
1) As of fairly recently, FiOS no longer blocks port 80 (which I found out by accident with my friend-with-FiOS's help)
2) FiOS isn't available on my street after all.
Still some good suggestions.
posted by jozxyqk at 5:26 PM on June 23, 2009
But it turns out that the question is moot for 2 reasons:
1) As of fairly recently, FiOS no longer blocks port 80 (which I found out by accident with my friend-with-FiOS's help)
2) FiOS isn't available on my street after all.
Still some good suggestions.
posted by jozxyqk at 5:26 PM on June 23, 2009
This thread is closed to new comments.
posted by AzraelBrown at 6:53 AM on May 24, 2009