LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-22-2008, 03:04 PM   #1
Serapis
LQ Newbie
 
Registered: Mar 2004
Location: Germany
Distribution: Centos 5
Posts: 26

Rep: Reputation: 15
Question Subdomains with Apache 2.2.3 - vhost or rewrite rule?


Hello all!

I am seriously confused how to set up a subdomain correctly.
I browsed the web via google, browsed this forum and other resources.

Either I am dumb, blind, or just deeply confused.
At the moment my subs just don't seem to work :-/

What I did so far:
I created the subdomain (sub.domain.com) on the DNS server and pointed it to the IP (static) of my server (123.123.123.123). This is where the domain (domain.com) is located as well.

What I want:
  • The domain (domain.com) has its doc root within the file folder of /home/.srv/domain.com/pub.
  • The subdomain (sub.domain.com) shall have its doc root within the file folder of /home/.srv/domain.com/pub/sub.


Then I read about different ways of making subdomains:
  1. make a new namebased vhost
  2. use the RewriteEngine in vhost domain.com

What I tried with Option 1):
I created a new vhost for the subdomain with following configuration:
Code:
DocumentRoot "/home/.srv/domain.com/pub/sub"
ServerName sub.domain.com
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
 
<Directory "/home/.srv/domain.com/pub/sub">
allow from all
Options +Indexes
</Directory>
The domain.com vhost itself has following configuration:

Code:
DocumentRoot /home/.srv/domain.com/pub
ServerName domain.com
ServerAlias www.domain.com
 
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
 
<Directory "/home/.srv/domain.com/pub">
allow from all
Options +Indexes
</Directory>
 
<Directory "/home/.srv/domain.com/pub/webdav">
# [...] I cut this out. I dont think this is of importance here
</Directory>
 
<Directory "/home/.srv/domain.com/pub/stats">
AuthType Basic
AuthName "Restricted Access"
order deny,allow
AuthBasicProvider file
AuthUserFile /home/.srv/domain.com/admin4pub/.passwd
require valid-user
</Directory>

As I saw this does not work, I tried the rewrite stuff (Option 2):

I extended the domain.com vhost config with some rewrite rules:

Code:
DocumentRoot /home/.srv/domain.com/pub
ServerName domain.com
ServerAlias www.domain.com
 
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
 
RewriteEngine on
RewriteOptions Inherit
RewriteLog "/var/log/httpd/rewrite.log"
RewriteLogLevel 9
 
#RewriteCond     %{HTTP_HOST}       ^www\.domain\.com$
RewriteCond     %{HTTP_HOST}       ^domain\.com$
RewriteRule     ^(.+)              http://www.domain.com   [NE,L,R]
 
RewriteCond     %{HTTP_HOST}       ^www\.sub(.+)\.domain\.com$
RewriteCond     %{HTTP_HOST}       ^sub\.domain\.com$
RewriteRule     ^(.+)              http://www.domain.com/sub [NE,L,R]
 

<Directory "/home/.srv/domain.com/pub">
allow from all
Options +Indexes
</Directory>
 

<Directory "/home/.srv/domain.com/pub/webdav">
# [...] I cut this out. I dont think this is of importance here
</Directory>
 
<Directory "/home/.srv/domain.com/pub/stats">
AuthType Basic
AuthName "Restricted Access"
order deny,allow
AuthBasicProvider file
AuthUserFile /home/.srv/domain.com/admin4pub/.passwd
require valid-user
</Directory>

... but had no luck with this either.
It seems it doesnt matter, what I try - I always end at http://domain.com when I enter http://sub.domain.com into the webbrowser.

I know it should be that difficult to make subdomains, but I really cant figure out what I am doing wrong - is it so obvious, that I cant find it ?

Please help me

Thank you in advance!
 
Old 01-22-2008, 03:27 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
there should be very little to do really. if you have the files all within the main directory, (which may or may not make much sense depending on who owns those subdomains and such...) then you wouldn't need a Directory directive as it'll already be covered. It's pretty confusing in your info as you've removed the <virtualhost .. > tags... (unless it's some config layout i'm not familiar with), but the vhost should need little more than

Code:
<VirtualHost *>
DocumentRoot /home/.srv/pub/sub
ServerName sub.domain.com
</VirtualHost>
and that should be it... nothing else should be needed at all, everythign should be inherited from the global configuration.
 
Old 01-23-2008, 01:32 AM   #3
Serapis
LQ Newbie
 
Registered: Mar 2004
Location: Germany
Distribution: Centos 5
Posts: 26

Original Poster
Rep: Reputation: 15
Question Thats weird

Hmm thats weird.
Well, if ya say my domain.com and sub.domain.com configs are correct, I gonna try switching the Default Server Config for a very short and plain one.

Right now it is the original default server one with only slight modifications.

Wish me luck
 
Old 01-23-2008, 10:22 AM   #4
Serapis
LQ Newbie
 
Registered: Mar 2004
Location: Germany
Distribution: Centos 5
Posts: 26

Original Poster
Rep: Reputation: 15
Question

Wow - now I am surprised.
When I move the vhost entry of the subdomain above the maindomain in the httpd.conf, then I get my subdomain - even if I enter http://domain.com.
When I move the vhost entry of the subdomain back below the maindomain in the httpd.conf, then I get the maindomain - even if I enter http://sub.domain.com.

Bah - That really makes me §$&$§.
After that I moved the doc root of the subdomain out of the maindomains doc root.
No change here either ...

May I again post my configs?
This time I include the global config as well (cleaned all the commented lines, so its easer to read)

I really hope somebody can help me here - It simply cant be that difficult to make a stupid sub. I must have overlooked something :/

Section 1: Global Environment
Code:
### 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.

ServerTokens ProductOnly
ServerRoot "/etc/httpd"
PidFile run/httpd.pid
TimeOut 120
KeepAlive on
MaxKeepAliveRequests 100
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
## 
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

# worker MPM
<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75 
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>


Listen *:80

#
# Dynamic Shared Object (DSO) Support
#
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so

#
# The following modules are not loaded by default:
#
#LoadModule cern_meta_module modules/mod_cern_meta.so
#LoadModule asis_module modules/mod_asis.so

#
# Load config files from the config directory "/etc/httpd/conf.d".
#
Include conf.d/*.conf

#
# ExtendedStatus controls whether Apache will generate "full" status
# information (ExtendedStatus On) or just basic information (ExtendedStatus
# Off) when the "server-status" handler is called. The default is Off.
#
#ExtendedStatus On

#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
#  . On SCO (ODT 3) use "User nouser" and "Group nogroup".
#  . On HPUX you may not be able to use shared memory as nobody, and the
#    suggested workaround is to create a user www and use that user.
#  NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
#  when the value of (unsigned)Group is above 60000; 
#  don't use Group #-1 on these systems!
#
User apache
Group apache

Section 2: 'Main' server configuration
Code:
### Section 2: 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin root@localhost

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make 
# redirections work in a sensible way.
#
#ServerName www.example.com:80

#
# UseCanonicalName: Determines how Apache constructs self-referencing 
# URLs and the SERVER_NAME and SERVER_PORT variables.
# When set "Off", Apache will use the Hostname and Port supplied
# by the client.  When set "On", Apache will use the value of the
# ServerName directive.
#
UseCanonicalName Off

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories). 
#
# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/html">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

</Directory>

#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid.  This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
# See also: http://httpd.apache.org/docs/misc/FAQ.html#forbidden
#
<IfModule mod_userdir.c>
    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    UserDir disable

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    # 
    #UserDir public_html

</IfModule>

#
# Control access to UserDir directories.  The following is an example
# for a site where these directories are restricted to read-only.
#
#<Directory /home/*/public_html>
#    AllowOverride FileInfo AuthConfig Limit
#    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
#    <Limit GET POST OPTIONS>
#        Order allow,deny
#        Allow from all
#    </Limit>
#    <LimitExcept GET POST OPTIONS>
#        Order deny,allow
#        Deny from all
#    </LimitExcept>
#</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the 
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var

#
# 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>

#
# TypesConfig describes where the mime.types file (or equivalent) is
# to be found.
#
TypesConfig /etc/mime.types

#
# 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

#
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type.  The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#
<IfModule mod_mime_magic.c>
#   MIMEMagicFile /usr/share/magic.mime
    MIMEMagicFile conf/magic
</IfModule>

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (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

#
# EnableMMAP: Control whether memory-mapping is used to deliver
# files (assuming that the underlying OS supports it).
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  On some systems, turning it off (regardless of
# filesystem) can improve performance; for details, please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablemmap
#
#EnableMMAP off

#
# EnableSendfile: Control whether the sendfile kernel support is 
# used to deliver files (assuming that the OS supports it). 
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
#EnableSendfile 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 logs/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

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
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

# "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this
# requires the mod_logio module to be loaded.
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here.  Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common

#
# If you would like to have separate agent and referer logfiles, uncomment
# the following directives.
#
#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/access_log combined

#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature On

#
# Aliases: Add here as many aliases as you need (with no limit). The format is 
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL.  So "/icons" isn't aliased in this
# example, only "/icons/".  If the fakename is slash-terminated, then the 
# realname must also be slash terminated, and if the fakename omits the 
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings.  If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

#
# WebDAV module configuration section.
# 
<IfModule mod_dav_fs.c>
    # Location of the WebDAV lock database.
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

#
# Redirect allows you to tell clients about documents which used to exist in
# your server's namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# Example:
# Redirect permanent /foo http://www.example.com/bar

#
# Directives controlling the display of server-generated directory listings.
#

#
# IndexOptions: Controls the appearance of server-generated directory
# listings.
#
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

#
# AddIcon* directives tell the server which icon to show for different
# files or filename extensions.  These are only displayed for
# FancyIndexed directories.
#
#[...]
#

# ReadmeName is the name of the README file the server will look for by
# default, and append to directory listings.
#
# HeaderName is the name of a file which should be prepended to
# directory indexes. 
ReadmeName README.html
HeaderName HEADER.html

#
# IndexIgnore is a set of filenames which directory indexing should ignore
# and not include in the listing.  Shell-style wildcarding is permitted.
#
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

#
# DefaultLanguage and AddLanguage [...] 

#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the 
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-8

#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-tar .tgz

#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz

# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi

#
# For files that include their own HTTP headers:
#
#AddHandler send-as-is asis

#
# For type maps (negotiated resources):
# (This is enabled by default to allow the Apache "It Worked" page
#  to be distributed in multiple languages.)
#
AddHandler type-map var

Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/var/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback
    </Directory>

</IfModule>
</IfModule>

#Browser match stuff [...]

#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>
#    SetHandler server-status
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

#
# Allow remote server configuration reports, with the URL of
#  http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-info>
#    SetHandler server-info
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#<IfModule mod_proxy.c>
#ProxyRequests On
#
#<Proxy *>
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Proxy>

#
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#
#ProxyVia On

#
# To enable a cache of proxied content, uncomment the following lines.
# See http://httpd.apache.org/docs/2.2/mod/mod_cache.html for more details.
#
#<IfModule mod_disk_cache.c>
#   CacheEnable disk /
#   CacheRoot "/var/cache/mod_proxy"
#</IfModule>
#

#</IfModule>
# End of proxy directives.
Sorry for that long Section 2. I cut out 2 long parts, whcih definately dont have impact on this issue: imagestuff and autolanguage. These parts were marked with [...]


Finally the last code section of my httpd.conf:
Section 3: Virtual Hosts:
Code:



### Section 3: Virtual Hosts


#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

#Just another vhost for someting else
<VirtualHost 300.300.300.300>  # In real life this is actual a valid IP-Adress
DocumentRoot /home/.srv/foo.com/pub
<Directory "/home/.srv/foo.com/pub">
allow from all
Options +Indexes
</Directory>
</VirtualHost>


### Here the problem child vhost start:
<VirtualHost *>
DocumentRoot /home/.srv/domain.com/pub
ServerName domain.com
ServerAlias www.domain.com
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

<Directory "/home/.srv/domain.com/pub">
allow from all
Options +Indexes
</Directory>

<Directory "/home/.srv/domain.com/pub/webdav">
# WebDAV einschalten
Dav on
AuthType Basic
AuthName DAV
AuthBasicProvider file
AuthUserFile /home/.srv/domain.com/admin4pub/.passwd
Require valid-user
# Alle Dateien als Plain Text zurückgegeben,
# auch Skripte
ForceType text/plain
CheckSpelling On
</Directory>

<Directory "/home/.srv/domain.com/pub/stats">
AuthType Basic
AuthName "Restricted Access"
order deny,allow
AuthBasicProvider file
AuthUserFile /home/.srv/domain.com/admin4pub/.passwd
require valid-user
</Directory>

<Directory "/home/.srv/domain.com/pub/masked">
AuthType Basic
AuthName "Restricted Access"
order deny,allow
AuthBasicProvider file
AuthUserFile /home/.srv/domain.com/admin4pub/.passwd
require valid-user
</Directory>
</VirtualHost>

##MY lovely sub I wanna create:
<VirtualHost *>
DocumentRoot "/home/.srv/domain.com/pub/sub"
ServerName sub.domain.com
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

<Directory "/home/.srv/domain.com/pub/sub">
allow from all
Options +Indexes
</Directory>
</VirtualHost>


## This one is working as intended, just for the completeness
<VirtualHost 400.400.400.400> # In real life this is actual a valid IP-Adress
DocumentRoot "/home/.srv/bar/pub"
DirectoryIndex index.htm index.html index.php
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
<Directory "/home/.srv/bar/pub">
AddType application/x-httpd-php php php4 php3 html htm
allow from all
Options None
AllowOverride All
</Directory>
</VirtualHost>

Any hints, advice or wisdom? Please!
Thank you in advance!
 
Old 01-23-2008, 10:42 AM   #5
nileshgr
Member
 
Registered: Aug 2007
Location: Pune, Maharashtra, India
Distribution: Gentoo
Posts: 84

Rep: Reputation: 16
Try the following code- (read more after code)

Code:
<Virtualhost sub.domain.com:80> #(or :* if u want all ports)
ServerName sub.domain.com:80 #(don't specify :80 if u want all ports)
ServerAdmin www@domain.com
DocumentRoot "/home/.srv/pub/sub"
AccessFileName .htaccess
<Directory "/home/.srv/pub/sub">
Order allow,deny
Allow from All
AllowOverride All #(set to None if u don't want overriding of options)
</Directory>
</VirtualHost>
But don't forget to create another VirtualHost for your top-level domain (domain.com) with the same options as specified in the Main Server Configuration (only directory options, etc. NO modules).
 
Old 01-23-2008, 11:15 AM   #6
Serapis
LQ Newbie
 
Registered: Mar 2004
Location: Germany
Distribution: Centos 5
Posts: 26

Original Poster
Rep: Reputation: 15
Just tried it - but it does not work ....
What small piece of config do I miss here?
 
Old 01-23-2008, 01:29 PM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well again, no need to bother with a <Directory> directive at all as that should be implicit, and if you define the host as sub.domain.com:80 then apache needs to actually locally bind to that fqdn, which if you are on a local server behind an internet firewall you won't have. so replace that with *:80 then it doesn't matter what the ip of the server actually is at all.

also in your config you've not apparently enabled the namevirtualhost directive at the top there. not sure what the default really is, but certainly uncomment that line.
 
Old 01-23-2008, 08:20 PM   #8
nileshgr
Member
 
Registered: Aug 2007
Location: Pune, Maharashtra, India
Distribution: Gentoo
Posts: 84

Rep: Reputation: 16
Quote:
Originally Posted by acid_kewpie View Post
well again, no need to bother with a <Directory> directive at all as that should be implicit, and if you define the host as sub.domain.com:80 then apache needs to actually locally bind to that fqdn, which if you are on a local server behind an internet firewall you won't have. so replace that with *:80 then it doesn't matter what the ip of the server actually is at all.

also in your config you've not apparently enabled the namevirtualhost directive at the top there. not sure what the default really is, but certainly uncomment that line.
NameVirtualHost is required for domains other than your domains. For example my mini server is hosting two domains mine & my frnd's.

for my primary domain & subdomains, i don't need NameVirtualHost but i need it only for the primary domain of my frnd.

ex. my domain is domain.com

i won't need NameVirtualHost for sub.domain.com (or even domain.com)

while if my frnd's domain is domain.net

then i need one NameVirtualHost for domain.net only and not for sub.domain.net
 
Old 01-25-2008, 04:28 AM   #9
Serapis
LQ Newbie
 
Registered: Mar 2004
Location: Germany
Distribution: Centos 5
Posts: 26

Original Poster
Rep: Reputation: 15
Well, the subdomain stuff worked finally!
Thank you alot for your patience and assistance :-)

I still have a small bug to figure out, but no time at the moment. Workload is very high. I will post an update of the other issue I have / had and the solution.
Hopefully it will help some other peops.

Greets!
 
  


Reply

Tags
apache, rewriterule, subdomain, vhost



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vhost configuration for CNAME wildcard subdomains leif_84 Linux - Server 1 01-08-2008 02:13 AM
Apache rewrite rule help kinetik Linux - Software 1 11-05-2007 11:18 AM
i need a rewrite rule!help arcow Linux - Enterprise 1 07-03-2007 05:37 AM
Apache: Alias is working on ssl vhost but not on mass vhost jonavogt Linux - Software 0 06-07-2005 02:05 PM
Help me make this rewrite rule in Apache ganninu Linux - General 8 01-07-2004 08:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration