400,741 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 400,741 IT Pros & Developers. It's quick & easy.

setup Apache for Subdomains

usafshah
100+
P: 104
HI all,
i have a domain abc.info on a remote server and its files are hosted on let say 217.56.34.12, and a subdomain subdomain.abc.info hosted on let say 80.45.1.26 ("/docs/www/") and another subdomain2.abc.info is also hosted on 80.45.1.26 ("/docs/www/domain2")
I'm running apache, what settings should i do in apache when as i type subdomain.abc.info and it opens the contents in /docs/www and as i type subdomain2.abc.info it opens the contents of /docs/www/subdomain2/

I have tried virtual host as follow

Expand|Select|Wrap|Line Numbers
  1. NameVirtualHost *
  2.  
  3. <VirtualHost *:80>
  4. ServerName subdomain.abc.info
  5. DocumentRoot "/docs/www"
  6. </VirtualHost>
  7.  
  8. <VirtualHost *:80>
  9. ServerName subdomain2.abc.info
  10. DocumentRoot "/docs/www/subdomain2"
  11. </VirtualHost>
but the thing is when i type subdomain.abc.info and subdomain.abc.info both open the contents of /docs/www



Best Regards
Jan 18 '07 #1
Share this Question
Share on Google+
12 Replies


usafshah
100+
P: 104
Apache is running on 80.45.1.26
Jan 18 '07 #2

Motoma
Expert 2.5K+
P: 3,235
I believe, and don't hold me to this, that you need to specify the domain name in the <VirtualHost> tag as well:

Expand|Select|Wrap|Line Numbers
  1. NameVirtualHost *
  2.  
  3. <VirtualHost subdomain.abc.info:80>
  4. ServerName subdomain.abc.info
  5. DocumentRoot "/docs/www"
  6. </VirtualHost>
  7.  
  8. <VirtualHost subdomain2.abc.info:80>
  9. ServerName subdomain2.abc.info
  10. DocumentRoot "/docs/www/subdomain2"
  11. </VirtualHost>
  12.  
Jan 18 '07 #3

usafshah
100+
P: 104
yeah checked with that as well, same thing again.

both subdomains pointing me to same content "/docs/www"
Jan 18 '07 #4

Motoma
Expert 2.5K+
P: 3,235
You don't happen to be using mod_ssl? If so, you will need to change the NameVirtualHost directive to include a port number:
Expand|Select|Wrap|Line Numbers
  1. NameVirtualHost *:80
  2.  
Jan 19 '07 #5

usafshah
100+
P: 104
mod_ssl settings are:

Expand|Select|Wrap|Line Numbers
  1. <IfModule mod_ssl.c>
  2.     Include conf/ssl.conf
  3. </IfModule>

and checked with NameVirtualHost *:80 as well, nothing happened :S
Jan 19 '07 #6

usafshah
100+
P: 104
this is the log of apache


[Fri Jan 19 23:37:07 2007] [warn] VirtualHost subdomain.abc.info:80 overlaps with VirtualHost subdomain2.abc.info:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Fri Jan 19 23:37:07 2007] [warn] NameVirtualHost *:80 has no VirtualHosts
Jan 19 '07 #7

usafshah
100+
P: 104
any solution ?
Jan 23 '07 #8

Motoma
Expert 2.5K+
P: 3,235
any solution ?
Sorry, I was away for the weekend.
What platform are you running this on?
What version of Apache are you using?
Would you object to posting your httpd.conf file here, either pasting it in, or putting a link for me to download and look over?
Jan 23 '07 #9

usafshah
100+
P: 104
Platform: Windows Xp sp2
Wampserver installed , here is the link
Apache 2.0.59
PHP 5.2.0 + PECL
MySQL 5.0.27


Expand|Select|Wrap|Line Numbers
  1.  
  2. ServerRoot "c:/wamp/apache2"
  3.  
  4.  
  5.  
  6. PidFile logs/httpd.pid
  7.  
  8.  
  9. Timeout 300
  10.  
  11.  
  12. KeepAlive On
  13.  
  14.  
  15. MaxKeepAliveRequests 100
  16.  
  17.  
  18. KeepAliveTimeout 15
  19.  
  20.  
  21. <IfModule mpm_winnt.c>
  22. ThreadsPerChild 250
  23. MaxRequestsPerChild  0
  24. </IfModule>
  25.  
  26.  
  27. Listen 80
  28.  
  29.  
  30. LoadModule access_module modules/mod_access.so
  31. LoadModule actions_module modules/mod_actions.so
  32. LoadModule alias_module modules/mod_alias.so
  33. LoadModule asis_module modules/mod_asis.so
  34. LoadModule auth_module modules/mod_auth.so
  35. #LoadModule auth_anon_module modules/mod_auth_anon.so
  36. #LoadModule auth_dbm_module modules/mod_auth_dbm.so
  37. #LoadModule auth_digest_module modules/mod_auth_digest.so
  38. LoadModule autoindex_module modules/mod_autoindex.so
  39. #LoadModule cern_meta_module modules/mod_cern_meta.so
  40. LoadModule cgi_module modules/mod_cgi.so
  41. #LoadModule dav_module modules/mod_dav.so
  42. #LoadModule dav_fs_module modules/mod_dav_fs.so
  43. LoadModule dir_module modules/mod_dir.so
  44. LoadModule env_module modules/mod_env.so
  45. #LoadModule expires_module modules/mod_expires.so
  46. LoadModule file_cache_module modules/mod_file_cache.so
  47. LoadModule headers_module modules/mod_headers.so
  48. LoadModule imap_module modules/mod_imap.so
  49. LoadModule include_module modules/mod_include.so
  50. LoadModule info_module modules/mod_info.so
  51. LoadModule isapi_module modules/mod_isapi.so
  52. LoadModule log_config_module modules/mod_log_config.so
  53. LoadModule mime_module modules/mod_mime.so
  54. LoadModule mime_magic_module modules/mod_mime_magic.so
  55. #LoadModule proxy_module modules/mod_proxy.so
  56. #LoadModule proxy_connect_module modules/mod_proxy_connect.so
  57. #LoadModule proxy_http_module modules/mod_proxy_http.so
  58. #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
  59. LoadModule negotiation_module modules/mod_negotiation.so
  60. LoadModule rewrite_module modules/mod_rewrite.so
  61. LoadModule setenvif_module modules/mod_setenvif.so
  62. #LoadModule speling_module modules/mod_speling.so
  63. LoadModule status_module modules/mod_status.so
  64. LoadModule unique_id_module modules/mod_unique_id.so
  65. LoadModule userdir_module modules/mod_userdir.so
  66. LoadModule usertrack_module modules/mod_usertrack.so
  67. LoadModule vhost_alias_module modules/mod_vhost_alias.so
  68. LoadModule php5_module "c:/wamp/php/php5apache2.dll"
  69.  
  70. ServerAdmin webmaster@localhost
  71.  
  72.  
  73. ServerName localhost:80
  74.  
  75.  
  76. UseCanonicalName Off
  77.  
  78.  
  79. DocumentRoot "C:/wamp/www"
  80.  
  81.  
  82. <Directory />
  83.     Options FollowSymLinks
  84.     AllowOverride None
  85. </Directory>
  86.  
  87.  
  88. <Directory "C:/wamp/www">
  89.  
  90.  
  91.     Options Indexes FollowSymLinks
  92.  
  93.  
  94.     AllowOverride all
  95.  
  96.  
  97.     Order Deny,Allow
  98.     Allow from all
  99.     Allow from 127.0.0.1
  100.  
  101.  
  102. </Directory>
  103.  
  104.  
  105. UserDir "c:/wamp/Apache2/users/"
  106.  
  107.  
  108. DirectoryIndex index.php index.php3 index.html index.htm index.html.var
  109.  
  110.  
  111. AccessFileName .htaccess
  112.  
  113.  
  114. <FilesMatch "^\.ht">
  115.     Order allow,deny
  116.     Deny from all
  117. </FilesMatch>
  118.  
  119.  
  120. TypesConfig conf/mime.types
  121.  
  122.  
  123. DefaultType text/plain
  124.  
  125.  
  126. <IfModule mod_mime_magic.c>
  127.     MIMEMagicFile conf/magic
  128. </IfModule>
  129.  
  130.  
  131. HostnameLookups Off
  132.  
  133.  
  134. ErrorLog ../logs/apache_error.log
  135.  
  136.  
  137. LogLevel warn
  138.  
  139.  
  140. LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  141. LogFormat "%h %l %u %t \"%r\" %>s %b" common
  142. LogFormat "%{Referer}i -> %U" referer
  143. LogFormat "%{User-agent}i" agent
  144.  
  145.  
  146. CustomLog ../logs/access.log common
  147.  
  148. ServerTokens Full
  149.  
  150.  
  151. ServerSignature On
  152.  
  153.  
  154. Alias /icons/ "c:/wamp/Apache2/icons/" 
  155.  
  156. <Directory "c:/wamp/Apache2/icons">
  157.     Options Indexes MultiViews
  158.     AllowOverride None
  159.     Order allow,deny
  160.     Allow from all
  161. </Directory>
  162.  
  163.  
  164. Alias /manual/ "c:/wamp/Apache2/htdocs/manual/"
  165.  
  166. <Directory "c:/wamp/Apache2/htdocs/manual">
  167.     Options Indexes
  168.     AllowOverride None
  169.     Order allow,deny
  170.     Allow from all
  171.  
  172.     <Files *.html>
  173.         SetHandler type-map
  174.     </Files>
  175.  
  176.     SetEnvIf Request_URI ^/manual/(de|en|es|fr|ja|ko|ru)/ prefer-language=$1
  177.     RedirectMatch 301 ^/manual(?:/(de|en|es|fr|ja|ko|ru)){2,}(/.*)?$ /manual/$1$2
  178. </Directory>
  179.  
  180.  
  181.  ScriptAlias /cgi-bin/ "c:/wamp/Apache2/cgi-bin/"
  182.  
  183.  ScriptAliased
  184. <Directory "c:/wamp/apache2/cgi-bin">
  185.     AllowOverride None
  186.     Options None
  187.     Order allow,deny
  188.     Allow from all
  189. </Directory>
  190.  
  191.  
  192. IndexOptions FancyIndexing VersionSort
  193.  
  194.  
  195. AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip
  196.  
  197. AddIconByType (TXT,/icons/text.gif) text/*
  198. AddIconByType (IMG,/icons/image2.gif) image/*
  199. AddIconByType (SND,/icons/sound2.gif) audio/*
  200. AddIconByType (VID,/icons/movie.gif) video/*
  201.  
  202. AddIcon /icons/binary.gif .bin .exe
  203. AddIcon /icons/binhex.gif .hqx
  204. AddIcon /icons/tar.gif .tar
  205. AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
  206. AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
  207. AddIcon /icons/a.gif .ps .ai .eps
  208. AddIcon /icons/layout.gif .html .shtml .htm .pdf
  209. AddIcon /icons/text.gif .txt
  210. AddIcon /icons/c.gif .c
  211. AddIcon /icons/p.gif .pl .py
  212. AddIcon /icons/f.gif .for
  213. AddIcon /icons/dvi.gif .dvi
  214. AddIcon /icons/uuencoded.gif .uu
  215. AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
  216. AddIcon /icons/tex.gif .tex
  217. AddIcon /icons/bomb.gif core
  218.  
  219. AddIcon /icons/back.gif ..
  220. AddIcon /icons/hand.right.gif README
  221. AddIcon /icons/folder.gif ^^DIRECTORY^^
  222. AddIcon /icons/blank.gif ^^BLANKICON^^
  223.  
  224.  
  225. DefaultIcon /icons/unknown.gif
  226.  
  227.  
  228. ReadmeName README.html
  229. HeaderName HEADER.html
  230.  
  231.  
  232. IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
  233.  
  234.  
  235. AddLanguage ca .ca
  236. AddLanguage cs .cz .cs
  237. AddLanguage da .dk
  238. AddLanguage de .de
  239. AddLanguage el .el
  240. AddLanguage en .en
  241. AddLanguage eo .eo
  242. AddLanguage es .es
  243. AddLanguage et .et
  244. AddLanguage fr .fr
  245. AddLanguage he .he
  246. AddLanguage hr .hr
  247. AddLanguage it .it
  248. AddLanguage ja .ja
  249. AddLanguage ko .ko
  250. AddLanguage ltz .ltz
  251. AddLanguage nl .nl
  252. AddLanguage nn .nn
  253. AddLanguage no .no
  254. AddLanguage pl .po
  255. AddLanguage pt .pt
  256. AddLanguage pt-BR .pt-br
  257. AddLanguage ru .ru
  258. AddLanguage sv .sv
  259. AddLanguage zh-CN .zh-cn
  260. AddLanguage zh-TW .zh-tw
  261.  
  262.  
  263. LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
  264.  
  265.  
  266. ForceLanguagePriority Prefer Fallback
  267.  
  268.  
  269. AddCharset ISO-8859-1  .iso8859-1 .latin1
  270. AddCharset ISO-8859-2  .iso8859-2 .latin2 .cen
  271. AddCharset ISO-8859-3  .iso8859-3 .latin3
  272. AddCharset ISO-8859-4  .iso8859-4 .latin4
  273. AddCharset ISO-8859-5  .iso8859-5 .latin5 .cyr .iso-ru
  274. AddCharset ISO-8859-6  .iso8859-6 .latin6 .arb
  275. AddCharset ISO-8859-7  .iso8859-7 .latin7 .grk
  276. AddCharset ISO-8859-8  .iso8859-8 .latin8 .heb
  277. AddCharset ISO-8859-9  .iso8859-9 .latin9 .trk
  278. AddCharset ISO-2022-JP .iso2022-jp .jis
  279. AddCharset ISO-2022-KR .iso2022-kr .kis
  280. AddCharset ISO-2022-CN .iso2022-cn .cis
  281. AddCharset Big5        .Big5       .big5
  282. # For russian, more than one charset is used (depends on client, mostly):
  283. AddCharset WINDOWS-1251 .cp-1251   .win-1251
  284. AddCharset CP866       .cp866
  285. AddCharset KOI8-r      .koi8-r .koi8-ru
  286. AddCharset KOI8-ru     .koi8-uk .ua
  287. AddCharset ISO-10646-UCS-2 .ucs2
  288. AddCharset ISO-10646-UCS-4 .ucs4
  289. AddCharset UTF-8       .utf8
  290.  
  291.  
  292. AddCharset GB2312      .gb2312 .gb 
  293. AddCharset utf-7       .utf7
  294. AddCharset utf-8       .utf8
  295. AddCharset big5        .big5 .b5
  296. AddCharset EUC-TW      .euc-tw
  297. AddCharset EUC-JP      .euc-jp
  298. AddCharset EUC-KR      .euc-kr
  299. AddCharset shift_jis   .sjis
  300.  
  301.  
  302. AddType application/x-compress .Z
  303. AddType application/x-gzip .gz .tgz
  304. AddType application/x-httpd-php .php
  305. AddType application/x-httpd-php .php3
  306.  
  307.  
  308.  
  309. AddHandler type-map var
  310.  
  311.  
  312. BrowserMatch "Mozilla/2" nokeepalive
  313. BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
  314. BrowserMatch "RealPlayer 4\.0" force-response-1.0
  315. BrowserMatch "Java/1\.0" force-response-1.0
  316. BrowserMatch "JDK/1\.0" force-response-1.0
  317.  
  318.  
  319. BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
  320. BrowserMatch "MS FrontPage" redirect-carefully
  321. BrowserMatch "^WebDrive" redirect-carefully
  322. BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
  323. BrowserMatch "^gnome-vfs" redirect-carefully
  324. BrowserMatch "^XML Spy" redirect-carefully
  325. BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
  326.  
  327.  
  328. <IfModule mod_ssl.c>
  329.     Include conf/ssl.conf
  330. </IfModule>
  331.  
  332.  
  333.  
  334. NameVirtualHost *:80
  335.  
  336.  
  337. <VirtualHost subdomain.abc.info:80>
  338.  
  339. ServerName subdomain.abc.info
  340. DocumentRoot "C:/wamp/www"
  341.  
  342. </VirtualHost>
  343.  
  344. <VirtualHost subdomain2.abc.info:80>
  345.  
  346. ServerName subdomain2.abc.info
  347. DocumentRoot "C:/wamp/www/webmail"
  348.  
  349. </VirtualHost>
  350.  
  351.  
  352.  
  353. Include "c:/wamp/apache2/conf/alias/phpmyadmin.conf"
  354. Include "c:/wamp/apache2/conf/alias/sqlitemanager.conf"
  355.  
Jan 23 '07 #10

Motoma
Expert 2.5K+
P: 3,235
Sorry for the long delay.
I have WAMP running on my desktop at work for testing purposes, and here is the solution that worked for me.

You had a line that said simply
Expand|Select|Wrap|Line Numbers
  1. ScriptAliased
I had to remove this line for Apache to even start.

In your virtual host section, you have the following set up:
Expand|Select|Wrap|Line Numbers
  1. <VirtualHost subdomain.abc.info:80>
  2.   ServerName subdomain.abc.info
  3.   DocumentRoot "C:/wamp/www"
  4. </VirtualHost>
  5.  
  6. <VirtualHost subdomain2.abc.info:80>
  7.   ServerName subdomain2.abc.info
  8.   DocumentRoot "C:/wamp/www/webmail"
  9. </VirtualHost>
  10.  
Replace that with this:
Expand|Select|Wrap|Line Numbers
  1. <VirtualHost *:80>
  2.   ServerName subdomain.abc.info
  3.   DocumentRoot /wamp/www
  4. </VirtualHost>
  5.  
  6. <VirtualHost *:80>
  7.   ServerName subdomain2.abc.info
  8.   DocumentRoot /wamp/www/webmail
  9. </VirtualHost>
  10.  
And everything should run smoothly.
Jan 24 '07 #11

usafshah
100+
P: 104
Yesssssssssssss !!! :D


worked !!!! thanks man you are genious :P
Jan 25 '07 #12

Motoma
Expert 2.5K+
P: 3,235
Glad to help.
Jan 25 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.