Solved

Apache 2.2 - Multiple  Ports

Posted on 2007-03-18
15
226 Views
Last Modified: 2012-05-05
I asked this question before but got no decent answer. I know it's possible.

I have 2 codebases, I want them served using the same instance of apache 2.2, but on different ports (On windows XP).

Can someone please tell me what I need to do in the config file to set this up? Thanks!
0
Comment
Question by:basiclife
  • 8
  • 7
15 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 18743694
I am not sure what you mean by 2 bodebases, but I would assume that you can create two virtual hosts and specify the ports you want to use there:

<Virtualhost 1.2.3.4:81>
Servername codebase1
"other required virtual hosts statments>
</Virtualhost>


<Virtualhost 1.2.3.4:82>
Servername codebase2
"other required virtual hosts statments>
</Virtualhost>
 
0
 
LVL 57

Expert Comment

by:giltjr
ID: 18743700
Now just remember that when somebody want to get to codebase1 they will need to enter:

     http://codebase1:81

and when they want to get to codebase2 it would be:

     http://codebase2:82

0
 
LVL 5

Author Comment

by:basiclife
ID: 18743843
That sounds like exactly what I need. by codebases, I suppose I mean document roots....

Will give it a try and be back to you ASAP
0
 
LVL 5

Author Comment

by:basiclife
ID: 18743853
Ok I have:

Listen 80
Listen 81

<VirtualHost <myip>:81>
      ServerName <myip>
      DocumentRoot "D:/Webserver/Test"
      Options Indexes FollowSymLinks
</VirtualHost>

and the main config points to a different directory...

In theory, 80 should be my main server, 81 should be my test environment, but both ports are pointing to the normal codebase, ignoring the virtual host... Any suggestions?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 18744124
Do you have another virtual host definition?  If not, then your "main server" is your only server which is "D:/Webserver/Test"

If you have another virtual host definition, is it the 1st virtual host definition in your config file?

When doing virtual hosts you must define each virtual host specifically.  The "main" server is the first virtual host defined, also called the default host.

So you may need to add:

<VirtualHost <myip>:80>
      ServerName <myip2>
      DocumentRoot "D:/Webserver/Default"
      Options Indexes FollowSymLinks
</VirtualHost>

BEFORE the other virtual host definition.
0
 
LVL 5

Author Comment

by:basiclife
ID: 18744133
So even though it works with no vhost definitions, you need to have to add it again if you use vhosts?

I'll give it a ry. am off to bed now but will get back to you tomorrow. thanks!
0
 
LVL 57

Expert Comment

by:giltjr
ID: 18744217
Correct.  With no vhost defintions there is only "one" site.

Once you start using virtual hosts there are mutliple sites.  The default site, the first virutual host defined in your configuration file, and then all of the other sites.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Author Comment

by:basiclife
ID: 18770941
Ok, I have:


<VirtualHost <IP>:80>
      ServerName <IP>:80
      DocumentRoot "D:/Webserver/Live"
</VirtualHost>

<VirtualHost <IP>:81>
      ServerName <IP>:81
      DocumentRoot "D:/Webserver/Test"
</VirtualHost>

      Listen 80
      Listen 81


I have tried with and without the port number on the servername directive. unfortunately, I'm STILL getting "D:/Webserver/Live" on both 80 and 81

Any suggestions? (and yes, I've restarted, etc...)
0
 
LVL 57

Accepted Solution

by:
giltjr earned 500 total points
ID: 18771521
What you have looks good.  You can go to:

     http://httpd.apache.org/docs/2.0/vhosts/examples.html

and search on the string:

     "Running different sites on different ports."

and it will show you an example that is "just like" what you have.  The only differnes is that you are on Windows and their example is for *nix.  I am at work and do not have access to my server to test (but it is Linux, so there could be somethind weird with Windows).  So I will need to get back to you latter on tonight after I test you definitions on mine.

But a few questions until then:

Do you have any alias statments for either of these directories?

Do you refere to these aliases within your web pages?

Do you actually have a different index.html (or what ever you use in the DirectoryIndex)   file in each of the documentroots?

I spent 3 days trying to figure out why a virtual host setup was not working only to find out the person that actually loaded the web pages put the same exact pages in both document roots.
0
 
LVL 5

Author Comment

by:basiclife
ID: 18771711
I have 2 sub-folders - /Test and /Live, I have an index.php in each, one prints "Test", tthe other prints (surprise!) "Live" - just so I can confirm where the page is being served from (and I did double-check to make sure I hasn't mconfused them...)

So as far as I can tell, it should be different. I've looked at the link you sent, that's what I based my config on.

Any help you can provide would be greatly appreciated.

Thanks!
0
 
LVL 5

Author Comment

by:basiclife
ID: 18773499
Oh and apologies, but more complete answer: no, no aliases and (currently) no webpages as such, jsut VERY small index.php 's ....
0
 
LVL 5

Author Comment

by:basiclife
ID: 18787971
For some reason using _default_ instead of the IP address in the virtualhost directoves worked (suggested by someone on apachelounge.com

I'm going to award the points as you've been so helpful, but with a grade of C as the answer wasn't  correct. For the record, I suspect this is something buggy with the windows implementation as all changes were as-per the manual.

Thanks for your help!
0
 
LVL 57

Expert Comment

by:giltjr
ID: 18788048
Ummm, interesting.  I setup Apache 2.2 and 2.0 the the exact statements (of couse with my comptuers IP address) you had under Windows XP and it worked just fine without using _default_.

The only way I can think that what you had is that the IP address you coded on the virtual host statments is not a valid IP address for your computer.
0
 
LVL 5

Author Comment

by:basiclife
ID: 18788664
Possibly so... but I tried with both my internal and external IPs so I'm really not sure WTH is going on. Sorry for the C - I tend to go with A, but can't really justify it for no answer.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 18789974
Oh, I really don't care about the grade, in fact would not have minded if you had asked for a refund.  I am more concerned as to why it was not working for you.  What Apache were you using?  All _default_ does is tell Apache to listen on all IP addresses assigned to the host.  Say you have 3 IP addresses on your computer:

    1.1.1.1
    1.1.2.1
    1.1.3.1

If you had:

     <VirtualHost 1.1.1.1:80>
     "virtualhost defs"
     </VirtualHost>
    <VirtualHost 1.1.1.1:81
     "virtualhost defs"
     </VirtualHost

Then any requests to 1.1.2.1 or 1.1.3.1 would fail.  Only requests to 1.1.1.1, for either port, would actually work.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now