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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple domains in Apache on Ubuntu

Status
Not open for further replies.

oxygene

Technical User
Mar 23, 2002
66
CA
I have tried to read many FAQ's and websites but cannot get a second domain to work in Apache.

The first domain works fine at rtrip.net. The second one eltms.net does not work and keeps pulling up rtrip.net.

Here are my files for anyone who can help me.

In /etc/apache2/httpd.conf: I added NameVirtualHost *:80 at the end of the file.

In :/etc/apache2/sites-available: I created a new file called eltms.net and this is what I put in the file:

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin webldamin@rtrip.net
DocumentRoot "/var/www"
ServerName ServerAlias rtrip.net
ErrorLog "/var/log/apache2/error.log"
CustomLog "/var/log/apache2/access.log" common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webldamin@rtrip.net
DocumentRoot "/var/ ServerName ServerAlias eltms.net
ErrorLog "/var/ CustomLog "/var/ common
</VirtualHost>
-------------------------
I enabled the site with a2ensite eltms.net and reloaded apache.

/etc/hosts:

127.0.0.1 localhost
127.0.0.1 rtrip.net
127.0.0.1 eltms.net
192.168.1.3 rtrip.net rtrip.net
127.0.1.1 rtrip.net
192.168.1.1 gateway
192.168.1.2 caslim.rtrip.lan caslim
192.168.1.4 crain.rtrip.lan crain
192.168.1.7 cbot.rtrip.lan
192.168.1.8 cnbot.rtrip.lan
192.168.1.14 ctrench.rtrip.lan ctrench

Can anyone help me to get eltms.net to serve it's own page that is different from rtrip.net? Thanks.




Life is what you make it.
 
Does apache know to read this file? To get apache to read other config files you need to use the Include directive. Red Hat for example, uses multiple config files. The main config file is /etc/httpd/conf/httpd.conf. There is also a directory called /etc/httpd/conf.d/ which holds all the other config files. The main (httpd.conf) has a line that reads "Include conf.d/*.conf". So all I had to do is create a file called vhosts and apache reads it every time it starts. Sometimes you nee to make sure the UseCannonicalName directive is set to off. If these seem to be correct, try switching ServerName of each vhost. By default apache will use the first vhost defined as the default. If it starts using the other one after switching, you know the problem is with apache resolving multiple hosts. When you use multiple vhosts, the main server will never be served so the ServerName Directive in httpd.conf should be commented out or set to localhost. Remember, any time you edit a config file, you need to restart apache.
 
I will look at some of these settings and post back with the results. Thanks so far.

Life is what you make it.
 
Do you have a sites-enabled directory?

That is where my active virtual hosts go, from the pool of the of the sites-available.
 
I verified the settings I have and to me they look correct. Can anyone let me know if the virual host file I posted above for eltms.net looks correct.

I also don't know what to put in the vhosts file.

I do have a sites-enabled directory and I eneabled the site by running a2ensite eltms.net.

The file eltms.net shows up in the sites-enabled directory.

Life is what you make it.
 
I think if we back u a little we can go over some of the basics. First open your main config file. In most case it's httpd.conf but ubuntu calls it something else. Look for the ServerRoot directive. It will point to the directory where apache has all its config and log file sub-directories. Now look for the Includes directive. It should point to a directory off the ServerRoot and use a wild card for file name. It may be something like /etc/apache2/sites-available/*.conf. Notice the *.conf at the end. That way any file in /etc/apache2/sites-available with a .conf extention will be read along with the main config file. Now you want all you virtual host definitions to be in one file. Let's call it /etc/apache2/sites-available/vhosts.conf. So just copy all you vhost containers to that file. A vhost container starts with <VirtualHost *:80> and ends with </VirtualHost *:80>. Something you said earlier made me think that you created a file for each vhost and put that file in the vhost's DocumentRoot. That would be wrong. All vhosts should be in one file which is included in the Include directive. There are times when you may want two differnt vhost files and that is when you are using both name based addressing which is what you are doing, and ip based addressing which is something you must do if you have more than one ssl site.
 
I may have to correct myself a little here. I am assuming that /etc/apache2/sites-available is where your config files are for Ubuntu. This may be however, where your vhost's web spaces go. So to clarify a bit, your main config file is the one that gets read when apache starts. If you have config directives not in the main, you must point to them with the Include directive. This is important because of the way apache works. When an http request comes in on port 80, apache answers the request and reads the header that contains the domain name. Apache uses your vhost containers to resolve the request. To do that it looks at the ServerName and ServerAlias directives in each container. When it finds a match, it looks at the DocumentRoot and serves the index it finds there. If I can add just one more thing, the ServerName directive should be commented out in the main configs when using virtual hosts. If you get an error message at boot up saying that a fully quallified domain name can't be found, you know apache is not reading your vhost file. Check the path and file extention for the Include directive.
 
Thanks for the tips above. Been busy but tried a number of changes today and still cannot get the 2nd site to work.

Rtrip.net works fine but eltms.net does not work.

When I restart Apache I get the following error:

[Sat Jul 04 22:05:08 2009] [warn] NameVirtualHost *:0 has no VirtualHosts
[Sat Jul 04 22:05:08 2009] [warn] NameVirtualHost *:80 has no VirtualHosts


I've already ripped out my hair. I'm looking for a way to put the strands back in so I can rip it out again.

Life is what you make it.
 
My current virtual host file for the second domain is:

#
# Eltms.net (/etc/apache2/sites-available/#
<VirtualHost *:80>
ServerAdmin webldamin@rtrip.net
ServerName ServerAlias eltms.net

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/
# CGI Directory
ScriptAlias /cgi-bin/ /var/ <Location /cgi-bin>
Options +ExecCGI
</Location>


# Logfiles
ErrorLog /var/others/eltms.net/logs/error.log
CustomLog /var/others/eltms.net/logs/access.log combined
</VirtualHost>


Life is what you make it.
 
My default file for rtrip.net is:

<VirtualHost *:80>
ServerAdmin webldamin@rtrip.net
ServerName rtrip.net
ServerAlias *.rtrip.net
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/ Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


Life is what you make it.
 
I have tried all the steps above and the links to other websites above.

I also have the new domain eltms.net pointed to my rtrip.net address via no-ip.com but I can't even route to it locally by ip address on my LAN.

Life is what you make it.
 
Just to add, I am running Ubuntu 9.04 and have no other problems with the server.

When I enable eltms.net with a2ensite eltms.net it disables the default rtrip.net or if it doesn't then it routes eltms.net to rtrip.net/index.html so I never see eltms.net/index.html

Life is what you make it.
 
I have tried the vhosts in the same file and both files follow the same content as the second file as listed above by ChrisRChambelain.

I still am not able to route to eltms.net.

Here are the contents to /etc/apache2/sites-available:

-rw-r--r-- 1 root root 1010 2009-07-05 16:13 default
-rw-r--r-- 1 root root 7.2K 2009-06-19 23:54 default-ssl
-rw-r--r-- 1 root root 623 2009-07-05 16:03 eltms.net



Life is what you make it.
 
Here is my /etc/apache2/apache2.conf:

#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
#
# The configuration directives are grouped into three basic sections:
# 1. Directives that control the operation of the Apache server process as a
# whole (the 'global environment').
# 2. Directives that define the parameters of the 'main' or 'default' server,
# which responds to requests that aren't handled by a virtual host.
# These directives also provide default values for the settings
# of all virtual hosts.
# 3. Settings for virtual hosts, which allow Web requests to be sent to
# different IP addresses or hostnames and have them handled by the
# same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path. If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "/var/log/apache2/foo.log"
# with ServerRoot set to "" will be interpreted by the
# server as "//var/log/apache2/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
ServerRoot "/etc/apache2"
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#<IfModule !mpm_winnt.c>
#<IfModule !mpm_netware.c>
LockFile /var/lock/apache2/accept.lock
#</IfModule>
#</IfModule>

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 45

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 200

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 3

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value. If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog /var/log/apache2/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf

# Include all the user configurations:
Include /etc/apache2/httpd.conf

# Include ports listing
Include /etc/apache2/ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

#
# Define an access log for VirtualHosts that don't define their own logfile
CustomLog /var/log/apache2/other_vhosts_access.log vhost_combined

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 #

#
# Putting this all together, we can internationalize error responses.
#
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
# our collection of by-error message multi-language collections. We use
# includes to substitute the appropriate text.
#
# You can modify the messages' appearance without changing any of the
# default HTTP_<error>.html.var files by adding the line:
#
# Alias /error/include/ "/your/include/path/"
#
# which allows you to create your own set of files by starting with the
# /usr/share/apache2/error/include/ files and copying them to /your/include/path/,
# even on a per-VirtualHost basis. The default include files will display
# your Apache version number and your ServerAdmin email address regardless
# of the setting of ServerSignature.
#
# The internationalized error documents require mod_alias, mod_include
# and mod_negotiation. To activate them, uncomment the following 30 lines.

# Alias /error/ "/usr/share/apache2/error/"
#
# <Directory "/usr/share/apache2/error">
# AllowOverride None
# Options IncludesNoExec
# AddOutputFilter Includes html
# AddHandler type-map var
# Order allow,deny
# Allow from all
# LanguagePriority en cs de es fr it nl sv pt-br ro
# ForceLanguagePriority Prefer Fallback
# </Directory>
#
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var



# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
Include /etc/apache2/conf.d/

# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/

NameVirtualHost *:80

ServerName rtrip.net


Life is what you make it.
 
And the contents of /etc/apache2/ports.conf:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
# SSL name based virtual hosts are not yet supported, therefore no
# NameVirtualHost statement here
Listen 443
</IfModule>


Life is what you make it.
 
And the contents of /etc/apache2/httpd.conf:

# NameVirtualHost *:80

Life is what you make it.
 
And the contents of /etc/apache2/sites-enabled:

/etc/apache2/sites-enabled


Something must have gone wrong as I am now nat able to route to rtrip.net by name or ip addr.

Will reboot server to see if it is back online.

Life is what you make it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top