This is a discussion on Apache domain best practice?? within the Apache Web Server forums, part of the Web Server and Related Forums category; I have an apache 2.0.54 webserver that I want to setup to handle 10 small domains. In the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have an apache 2.0.54 webserver that I want to setup to handle 10
small domains. In the past I have setup each domain to listen on port 80, but burned a virtual ip in doing so. If possible I want to move away from assigning a virtual ip to each new domain. I tried setting up each domain using the same ip, but a different port i.e. 80, 8080, 8081, etc, however am having trouble with users then having to access the URL with the port i.e. www.testabc.com:8081 What is the best way or best practice when setting up an apache webserver to handle multiple domains, Thanks! |
|
|||
|
trp...@gmail.com wrote: > I have an apache 2.0.54 webserver that I want to setup to handle 10 > small domains. In the past I have setup each domain to listen on port > 80, but burned a virtual ip in doing so. If possible I want to move > away from assigning a virtual ip to each new domain. I tried setting > up each domain using the same ip, but a different port i.e. 80, 8080, > 8081, etc, however am having trouble with users then having to access > the URL with the port i.e. www.testabc.com:8081 > > What is the best way or best practice when setting up an apache > webserver to handle multiple domains, > > Thanks! use a single IP!! this is virtualhosting set you apache to listen on port 80 then HTTP/1.1 (what every modern user agent uses) sends a host header host: www.bbc.co.uk in the request, this is passed to apache which therefore knows what the browser is looking for, and you set rules in virtualhost stanzas that tell apache where each host is the first virtualhost stanza is always used when no other host header matches any other virtualhost block so it tends to make sense to have the first virtualhost a generic one see apache docs under virtualhosting <VirtualHost *> DocumentRoot /var/www/generic_not_found/public </VirtualHost> <VirtualHost *> DocumentRoot /var/www/example.com/public ServerName www.example.com ServerAlias example.com </VirtualHost> #etc... |
|
|||
|
On Oct 22, 6:10 pm, shimmyshack <matt.fa...@gmail.com> wrote:
> trp...@gmail.com wrote: > > I have an apache 2.0.54 webserver that I want to setup to handle 10 > > small domains. In the past I have setup each domain to listen on port > > 80, but burned a virtual ip in doing so. If possible I want to move > > away from assigning a virtual ip to each new domain. I tried setting > > up each domain using the same ip, but a different port i.e. 80, 8080, > > 8081, etc, however am having trouble with users then having to access > > the URL with the port i.e.www.testabc.com:8081 > > > What is the best way or best practice when setting up an apache > > webserver to handle multiple domains, > > > Thanks! > > use a single IP!! > this is virtualhosting > > set you apache to listen on port 80 > > then HTTP/1.1 (what every modern user agent uses) sends a host header > > host:www.bbc.co.uk > > in the request, this is passed to apache which therefore knows what > the browser is looking for, and you set rules in virtualhost stanzas > that tell apache where each host is > > the first virtualhost stanza is always used when no other host header > matches any other virtualhost block so it tends to make sense to have > the first virtualhost a generic one > > see apache docs under virtualhosting > > <VirtualHost *> > DocumentRoot /var/www/generic_not_found/public > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/example.com/public > ServerNamewww.example.com > ServerAlias example.com > </VirtualHost> > > #etc... Thanks for the quick response... Just to make sure I understand, would this work for example: <VirtualHost *> DocumentRoot /var/www/generic_not_found/public </VirtualHost> <VirtualHost *> DocumentRoot /var/www/example.com/public ServerName www.example.com ServerAlias example.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/test.com/public ServerName www.test.com ServerAlias test.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/project.com/public ServerName www.project.com ServerAlias project.com </VirtualHost> .... So in the above I am listening on port 80 and 1 ip address, but handling 3 different domains based on the ServerName in the VirtualHost definition. I guess I was thrown off a bit because what I gathered in the docs was that I could use the same ip, but only for subdomains, where here I actually have different domains. |
|
|||
|
On Oct 23, 1:21 am, trp...@gmail.com wrote:
> On Oct 22, 6:10 pm, shimmyshack <matt.fa...@gmail.com> wrote: > > > > > > > trp...@gmail.com wrote: > > > I have an apache 2.0.54 webserver that I want to setup to handle 10 > > > small domains. In the past I have setup each domain to listen on port > > > 80, but burned a virtual ip in doing so. If possible I want to move > > > away from assigning a virtual ip to each new domain. I tried setting > > > up each domain using the same ip, but a different port i.e. 80, 8080, > > > 8081, etc, however am having trouble with users then having to access > > > the URL with the port i.e.www.testabc.com:8081 > > > > What is the best way or best practice when setting up an apache > > > webserver to handle multiple domains, > > > > Thanks! > > > use a single IP!! > > this is virtualhosting > > > set you apache to listen on port 80 > > > then HTTP/1.1 (what every modern user agent uses) sends a host header > > > host:www.bbc.co.uk > > > in the request, this is passed to apache which therefore knows what > > the browser is looking for, and you set rules in virtualhost stanzas > > that tell apache where each host is > > > the first virtualhost stanza is always used when no other host header > > matches any other virtualhost block so it tends to make sense to have > > the first virtualhost a generic one > > > see apache docs under virtualhosting > > > <VirtualHost *> > > DocumentRoot /var/www/generic_not_found/public > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/example.com/public > > ServerNamewww.example.com > > ServerAlias example.com > > </VirtualHost> > > > #etc... > > Thanks for the quick response... Just to make sure I understand, would > this work for example: > > <VirtualHost *> > DocumentRoot /var/www/generic_not_found/public > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/example.com/public > ServerNamewww.example.com > ServerAlias example.com > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/test.com/public > ServerNamewww.test.com > ServerAlias test.com > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/project.com/public > ServerNamewww.project.com > ServerAlias project.com > </VirtualHost> > > ... > > So in the above I am listening on port 80 and 1 ip address, but > handling 3 different domains based on the ServerName in the > VirtualHost definition. I guess I was thrown off a bit because what I > gathered in the docs was that I could use the same ip, but only for > subdomains, where here I actually have different domains.- Hide quoted text - > > - Show quoted text - yup it sure would, with the caveat that you have to tell apache that its now in namevirtualhost mode. (you can keep the ip aliasing the way you had it) because apache listens on all ip addresses if you dont specify less (*:80) means listen on port 80 on all IPs, so <VirtualHost *> will work with your existing setup. NameVirtualHost *:80 #or NameVirtualHost * #or NameVirtualHost 10.10.10.12:80 .... #depending on what you need. <VirtualHost *> DocumentRoot /var/www/generic_not_found/public </VirtualHost> <VirtualHost *> DocumentRoot /var/www/example.com/public ServerName www.example.com ServerAlias example.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/test.com/public ServerName www.test.com ServerAlias test.com </VirtualHost> <VirtualHost *> DocumentRoot /var/www/project.com/public ServerName www.project.com ServerAlias project.com </VirtualHost> -------------------------- because you will probably only be using port 80 you could use this as well: <VirtualHost *:80> DocumentRoot /var/www/generic_not_found/public </VirtualHost> or even <VirtualHost 10.10.10.12:80> DocumentRoot /var/www/generic_not_found/public </VirtualHost> see its easy. you can now try on the command line telnet your_server_ ip 80 then copy this to the clipboard and simply paste in the command line and press enter twice GET / HTTP/1.1 host: www.project.com or GET / HTTP/1.1 host: project.com you will be served the default index from the www.project.com/ project.com site, or GET / HTTP/1.1 host: 127.0.0.1 will not match any, so it will served from the first vhost stanza, which is why having a catch all is useful - in case people use an OLD or user agent not compliant with HTTP/1.1 or miss off the host header in code you could consider writing "you must use an HTTP/1.1 sompliant user agent to view content on this server" mesage for the catch all vhost you can also use more advanced mass virtual hosting, which requires only that you create the file system structure, for the new host to work, its therefore called dynamic mass virtual hosting. http://httpd.apache.org/docs/2.2/mod...ost_alias.html |
|
|||
|
On Oct 23, 5:27 am, shimmyshack <matt.fa...@gmail.com> wrote:
> On Oct 23, 1:21 am, trp...@gmail.com wrote: > > > > > > > On Oct 22, 6:10 pm, shimmyshack <matt.fa...@gmail.com> wrote: > > > > trp...@gmail.com wrote: > > > > I have an apache 2.0.54 webserver that I want to setup to handle 10 > > > > small domains. In the past I have setup each domain to listen on port > > > > 80, but burned a virtual ip in doing so. If possible I want to move > > > > away from assigning a virtual ip to each new domain. I tried setting > > > > up each domain using the same ip, but a different port i.e. 80, 8080, > > > > 8081, etc, however am having trouble with users then having to access > > > > the URL with the port i.e.www.testabc.com:8081 > > > > > What is the best way or best practice when setting up an apache > > > > webserver to handle multiple domains, > > > > > Thanks! > > > > use a single IP!! > > > this is virtualhosting > > > > set you apache to listen on port 80 > > > > then HTTP/1.1 (what every modern user agent uses) sends a host header > > > > host:www.bbc.co.uk > > > > in the request, this is passed to apache which therefore knows what > > > the browser is looking for, and you set rules in virtualhost stanzas > > > that tell apache where each host is > > > > the first virtualhost stanza is always used when no other host header > > > matches any other virtualhost block so it tends to make sense to have > > > the first virtualhost a generic one > > > > see apache docs under virtualhosting > > > > <VirtualHost *> > > > DocumentRoot /var/www/generic_not_found/public > > > </VirtualHost> > > > > <VirtualHost *> > > > DocumentRoot /var/www/example.com/public > > > ServerNamewww.example.com > > > ServerAlias example.com > > > </VirtualHost> > > > > #etc... > > > Thanks for the quick response... Just to make sure I understand, would > > this work for example: > > > <VirtualHost *> > > DocumentRoot /var/www/generic_not_found/public > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/example.com/public > > ServerNamewww.example.com > > ServerAlias example.com > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/test.com/public > > ServerNamewww.test.com > > ServerAlias test.com > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/project.com/public > > ServerNamewww.project.com > > ServerAlias project.com > > </VirtualHost> > > > ... > > > So in the above I am listening on port 80 and 1 ip address, but > > handling 3 different domains based on the ServerName in the > > VirtualHost definition. I guess I was thrown off a bit because what I > > gathered in the docs was that I could use the same ip, but only for > > subdomains, where here I actually have different domains.- Hide quoted text - > > > - Show quoted text - > > yup it sure would, with the caveat that you have to tell apache that > its now in namevirtualhost mode. (you can keep the ip aliasing the way > you had it) because apache listens on all ip addresses if you dont > specify less (*:80) means listen on port 80 on all IPs, so > <VirtualHost *> will work with your existing setup. > > NameVirtualHost *:80 > #or NameVirtualHost * > #or NameVirtualHost 10.10.10.12:80 .... > #depending on what you need. > > <VirtualHost *> > DocumentRoot /var/www/generic_not_found/public > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/example.com/public > ServerNamewww.example.com > ServerAlias example.com > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/test.com/public > ServerNamewww.test.com > ServerAlias test.com > </VirtualHost> > > <VirtualHost *> > DocumentRoot /var/www/project.com/public > ServerNamewww.project.com > ServerAlias project.com > </VirtualHost> > > -------------------------- > because you will probably only be using port 80 you could use this as > well: > <VirtualHost *:80> > DocumentRoot /var/www/generic_not_found/public > </VirtualHost> > or even > <VirtualHost 10.10.10.12:80> > DocumentRoot /var/www/generic_not_found/public > </VirtualHost> > > see its easy. > > you can now try on the command line > telnet your_server_ ip 80 > > then copy this to the clipboard and simply paste in the command line > and press enter twice > > GET / HTTP/1.1 > host:www.project.com > > or > > GET / HTTP/1.1 > host: project.com > > you will be served the default index from thewww.project.com/ > project.com site, > > or > > GET / HTTP/1.1 > host: 127.0.0.1 > > will not match any, so it will served from the first vhost stanza, > which is why having a catch all is useful - in case people use an OLD > or user agent not compliant with HTTP/1.1 or miss off the host header > in code you could consider writing > "you must use an HTTP/1.1 sompliant user agent to view content on this > server" mesage for the catch all vhost > > you can also use more advanced mass virtual hosting, which requires > only that you create the file system structure, for the new host to > work, its therefore called dynamic mass virtual hosting.http://httpd.apache.org/docs/2.2/mod...st_alias.html- Hide quoted text - > > - Show quoted text - So I got this to work fine for port 80, however read that port 443 SSL does not work well with named virtual hosts. What is the best practice in this case? |
|
|||
|
On Oct 30, 4:12 pm, trp...@gmail.com wrote:
> On Oct 23, 5:27 am, shimmyshack <matt.fa...@gmail.com> wrote: > > > > > > > On Oct 23, 1:21 am, trp...@gmail.com wrote: > > > > On Oct 22, 6:10 pm, shimmyshack <matt.fa...@gmail.com> wrote: > > > > > trp...@gmail.com wrote: > > > > > I have an apache 2.0.54 webserver that I want to setup to handle 10 > > > > > small domains. In the past I have setup each domain to listen on port > > > > > 80, but burned a virtual ip in doing so. If possible I want to move > > > > > away from assigning a virtual ip to each new domain. I tried setting > > > > > up each domain using the same ip, but a different port i.e. 80, 8080, > > > > > 8081, etc, however am having trouble with users then having to access > > > > > the URL with the port i.e.www.testabc.com:8081 > > > > > > What is the best way or best practice when setting up an apache > > > > > webserver to handle multiple domains, > > > > > > Thanks! > > > > > use a single IP!! > > > > this is virtualhosting > > > > > set you apache to listen on port 80 > > > > > then HTTP/1.1 (what every modern user agent uses) sends a host header > > > > > host:www.bbc.co.uk > > > > > in the request, this is passed to apache which therefore knows what > > > > the browser is looking for, and you set rules in virtualhost stanzas > > > > that tell apache where each host is > > > > > the first virtualhost stanza is always used when no other host header > > > > matches any other virtualhost block so it tends to make sense to have > > > > the first virtualhost a generic one > > > > > see apache docs under virtualhosting > > > > > <VirtualHost *> > > > > DocumentRoot /var/www/generic_not_found/public > > > > </VirtualHost> > > > > > <VirtualHost *> > > > > DocumentRoot /var/www/example.com/public > > > > ServerNamewww.example.com > > > > ServerAlias example.com > > > > </VirtualHost> > > > > > #etc... > > > > Thanks for the quick response... Just to make sure I understand, would > > > this work for example: > > > > <VirtualHost *> > > > DocumentRoot /var/www/generic_not_found/public > > > </VirtualHost> > > > > <VirtualHost *> > > > DocumentRoot /var/www/example.com/public > > > ServerNamewww.example.com > > > ServerAlias example.com > > > </VirtualHost> > > > > <VirtualHost *> > > > DocumentRoot /var/www/test.com/public > > > ServerNamewww.test.com > > > ServerAlias test.com > > > </VirtualHost> > > > > <VirtualHost *> > > > DocumentRoot /var/www/project.com/public > > > ServerNamewww.project.com > > > ServerAlias project.com > > > </VirtualHost> > > > > ... > > > > So in the above I am listening on port 80 and 1 ip address, but > > > handling 3 different domains based on the ServerName in the > > > VirtualHost definition. I guess I was thrown off a bit because what I > > > gathered in the docs was that I could use the same ip, but only for > > > subdomains, where here I actually have different domains.- Hide quoted text - > > > > - Show quoted text - > > > yup it sure would, with the caveat that you have to tell apache that > > its now in namevirtualhost mode. (you can keep the ip aliasing the way > > you had it) because apache listens on all ip addresses if you dont > > specify less (*:80) means listen on port 80 on all IPs, so > > <VirtualHost *> will work with your existing setup. > > > NameVirtualHost *:80 > > #or NameVirtualHost * > > #or NameVirtualHost 10.10.10.12:80 .... > > #depending on what you need. > > > <VirtualHost *> > > DocumentRoot /var/www/generic_not_found/public > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/example.com/public > > ServerNamewww.example.com > > ServerAlias example.com > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/test.com/public > > ServerNamewww.test.com > > ServerAlias test.com > > </VirtualHost> > > > <VirtualHost *> > > DocumentRoot /var/www/project.com/public > > ServerNamewww.project.com > > ServerAlias project.com > > </VirtualHost> > > > -------------------------- > > because you will probably only be using port 80 you could use this as > > well: > > <VirtualHost *:80> > > DocumentRoot /var/www/generic_not_found/public > > </VirtualHost> > > or even > > <VirtualHost 10.10.10.12:80> > > DocumentRoot /var/www/generic_not_found/public > > </VirtualHost> > > > see its easy. > > > you can now try on the command line > > telnet your_server_ ip 80 > > > then copy this to the clipboard and simply paste in the command line > > and press enter twice > > > GET / HTTP/1.1 > > host:www.project.com > > > or > > > GET / HTTP/1.1 > > host: project.com > > > you will be served the default index from thewww.project.com/ > > project.com site, > > > or > > > GET / HTTP/1.1 > > host: 127.0.0.1 > > > will not match any, so it will served from the first vhost stanza, > > which is why having a catch all is useful - in case people use an OLD > > or user agent not compliant with HTTP/1.1 or miss off the host header > > in code you could consider writing > > "you must use an HTTP/1.1 sompliant user agent to view content on this > > server" mesage for the catch all vhost > > > you can also use more advanced mass virtual hosting, which requires > > only that you create the file system structure, for the new host to > > work, its therefore called dynamic mass virtual hosting.http://httpd.apache.org/docs/2.2/mod...lias.html-Hide quoted text - > > > - Show quoted text - > > So I got this to work fine for port 80, however read that port 443 SSL > does not work well with named virtual hosts. What is the best practice > in this case?- Hide quoted text - > > - Show quoted text - well you can create a signature for multiple hosts using cacert.org |