Problems with Apache Virtual Host


 
Thread Tools Search this Thread
Top Forums Web Development Problems with Apache Virtual Host
# 22  
Old 01-20-2014
You were right. Each and every vhost has to be in its own, separate, independent configuration file. Why this is, I do not know.

I was used to the old apache behavior, where config files were config files, and their contents defined the behavior, not their placement or name; the vhost directory was just an invitation to organize them better. Is this an ubuntu thing, or has apache changed that drastically?

In any case, solved. Thank you.

My config files, for posterity:

/etc/apache2/sites-available/mysite.com:
Code:
<VirtualHost *:80>
        ServerName mysite.com
        DocumentRoot /usr/share/wordpress
</VirtualHost>

Each individual subdomain is like /etc/apache2/sites-available/subdomain.mysite.com:

Code:
<VirtualHost *:80>
        ServerName subdomain.mysite.com
        DocumentRoot /usr/share/wordpress

        alias /wp-content/languages /srv/www/wp-content/subdomain.mysite.com/languages
        alias /wp-content/plugins /srv/www/wp-content/subdomain.mysite.com/plugins
        alias /wp-content/themes /srv/www/wp-content/subdomain.mysite.com/themes
        alias /wp-content/uploads /srv/www/wp-content/subdomain.mysite.com/uploads
</VirtualHost>

Then you can
Code:
a2ensite mysite.com
a2ensite subdomain.mysite.com
service apache2 reload

to get the virtual hosts online.

Last edited by Corona688; 01-20-2014 at 02:31 PM..
# 23  
Old 01-20-2014
Hi Corona look at the following... this time you will get what you want

Code:
root@Aix:/etc/apache2/sites-available# ls
akshay  corona  default  default-ssl
root@Aix:/etc/apache2/sites-available# cat default
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    
    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    
    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
root@Aix:/etc/apache2/sites-available# cat akshay 
<VirtualHost *:80>
    
    ServerName akshay.com
    
    DocumentRoot /var/www/akshay
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/akshay/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    
    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
root@Aix:/etc/apache2/sites-available# cat corona 
<VirtualHost *:80>
    
    ServerName corona.com
    
    DocumentRoot /var/www/corona
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/corona/>
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    
    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Code:
root@Aix:/var/www# ls
akshay  corona
root@Aix:/var/www# cat akshay/index.html 
<html>
      <head>
        <title>akshay.com</title>
      </head>
      <body>
            akshay.com
      </body>
    </html>

root@Aix:/var/www# cat corona/index.html 
<html>
      <head>
        <title>corona.com</title>
      </head>
      <body>
            corona.com
      </body>
    </html>

Code:
root@Aix:/var/www# cat /etc/hosts
127.0.0.1    localhost
127.0.1.1    Aix
127.0.0.1 akshay.com
127.0.0.1 corona.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Code:
root@Aix:/var/www# sudo a2ensite akshay
Site akshay already enabled

root@Aix:/var/www# sudo a2ensite corona
Site corona already enabled

root@Aix:/var/www# sudo a2dissite default
Site default already disabled

root@Aix:/var/www# sudo /etc/init.d/apache2 reload
 * Reloading web server config apache2                                                                     
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

clear cache and checkout corona.com and akshay.com on your browser
# 24  
Old 01-20-2014
Quote:
Originally Posted by Corona688
You were right. Each and every vhost has to be in its own, separate, independent configuration file. Why this is, I do not know.

I was used to the old apache behavior, where config files were config files, and their contents defined the behavior, not their placement or name; the vhost directory was just an invitation to organize them better. Is this an ubuntu thing, or has apache changed that drastically?

In any case, solved. Thank you.
Hey Brother,

I don't know, but it's been this way for many years; but I only use Ubuntu, so I cannot speak for other Linux distributions.

However, those commands like:

Code:
a2ensite your.cool.site.com

... are apache2 commands ( I think ) , not specific to Ubuntu (I did not confirm this, however), and those commands take a file in ../sites-available and simply create a symlink from ../sites-enabled.

Anyway, it's all moot now, since you got it working!
# 25  
Old 01-20-2014
OBTW, in one of the example posts above, each virtualhost file has the same log file directive:

Code:
CustomLog ${APACHE_LOG_DIR}/access.log combined

I know it's only an example, but just for the record, I recommend that you always keep separate access log and error log files for each virtual host and do not use the same file for all virtual hosts, combined into one log file.

I always have separate log file (access and error) with names that correspond to each virtual server.

These days, I'm getting so I put each logging (for each web site) in it's own directory (apache2, mysql, various site specific debug logs, etc) ; but that's not as important as just making sure your access and error logs are specific for each virtual host.
# 26  
Old 01-20-2014
Yes... Neo.. I just pasted same file and changed server name so.. as you said it's always good if there is a separate log file for access and error.
# 27  
Old 01-20-2014
All Ubuntu has is Include sites-enabled/ at the end of apache2.conf, which means 'concatenate everything inside sites-enabled then parse'. Not far different from the default configs on my other servers really. The apache documentation appears to agree, there's no extra magic to it.

I'm beginning to think I just fat-fingered something in my first attempts and got myself confused, stuck in a blind alley. A combined config should still work hypothetically. But I've been fighting with this so long I'm just thrilled that it works at all.

I will further refine these vhosts now that I have something that works, thank you for your suggestions. I kept them intentionally as simple as possible to rule out other problems.

Last edited by Corona688; 01-20-2014 at 03:27 PM..
# 28  
Old 01-20-2014
Quote:
Originally Posted by Akshay Hegde
Yes... Neo.. I just pasted same file and changed server name so.. as you said it's always good if there is a separate log file for access and error.
Yes, I understand. As mentioned, I wanted to point out that this was "an example" and not best practices. Ditto for having the same logfile for each virtual host as the same.

Quote:
Originally Posted by Corona688
All Ubuntu has is Include sites-enabled/ at the end of apache2.conf, which means 'concatenate everything inside sites-enabled then parse'.
There are other included directories like:

Code:
/etc/apache2/conf.d

.. and my experience is that we need to be caution when running many sites together and using these Include directives for directories.

For example, on many of my sites, I have a separate directive to include files are specific to each web site and only keep the "bare bones" files that must be common to each site in the common Include conf.d directory.

I have spent many an hour trying to fix problems related to these Include directives on a server running many "sites"...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Apache Virtual host issue

Hello, I am facing a very strange issue while setting a virtual host on apache to setup multiple websites using separate IPs. Virtual host is setup but when i am browsing the website it display content under /var/www/html and displaying site1 and site2 folder instead of access the content... (2 Replies)
Discussion started by: sunnysthakur
2 Replies

2. Solaris

Solaris 10 virtual - how do I tell physical host?

uname -a reports type Generic so I know its virtual. Assume its an ldom somewhere. How do I find out what physical host server is? (4 Replies)
Discussion started by: psychocandy
4 Replies

3. Red Hat

Apache virtual host config vs global config problem

Hi folks, I am trying to configure Apache webserver and also a virtual host inside this webserver. For Global server config: /var/www/html/index.html For virtual host config: /var/www/virtual/index.html Both client10 & www10 are pointing to 192.168.122.10 IP address. BUT, MY... (1 Reply)
Discussion started by: freebird8z
1 Replies

4. Red Hat

Apache question - virtual host related

Hi folks, I recently read about Apache virtual host and was able to configure that as well. I used name based virtual host (lets say http://vhost1.example.com) and it worked just fine. Then I configured another named based virtual host on same apache server (lets say http://vhost2.example.com)... (2 Replies)
Discussion started by: freebird8z
2 Replies

5. Solaris

Change hostID of Solaris 10 virtual/guest machine installed by Virtual Box 4.1.12 on Windows-XP host

Trying to set or modify the randomly set hostID of a Solaris 10 virtual/guest machine that I installed on a Windows-XP host machine (using Virtual Box 4.1.12). I was able to set/modify the hostname of the Solaris 10 virtual/guest machine during installation as well as via the Virtual Box... (4 Replies)
Discussion started by: Matt_VB
4 Replies

6. Red Hat

Virtual Host Apache

Hi, I have set up the following virtual host but it cannot find the URL? Apache is running fine and I have disabled iptables. Within the document root I have the following file index.html displaying a sample text message. Any ideas what my problem might be? httpd.conf: ... (2 Replies)
Discussion started by: Duffs22
2 Replies

7. Solaris

Unix virtual host detection

Is it possible to reliably detect the virtual host of a Sun Solaris box, within a shell or Perl script? Can a system have multiple virtual host or not host at all ? I was recently made aware of hostname command, but was not sure if this option was the only one available. Any help is much... (3 Replies)
Discussion started by: Meridian
3 Replies

8. Solaris

Unix virtual host detection

I have a need to write scripts that can reliably determine the virtual host of a Sun Solaris system. (1 Reply)
Discussion started by: Meridian
1 Replies

9. UNIX for Advanced & Expert Users

Resolving Aliases and Virtual IP's on a Host

I am currently going through the servers in our network and trying to compile a list of the current aliases for each box and any virtual IP addresses. I can check for the ones that are supposed to be there but how do I list the ones that I don't even know exist? ANY help would be greatly... (1 Reply)
Discussion started by: Scott Pullen
1 Replies

10. UNIX for Dummies Questions & Answers

Apache virtual host

Would this be the correct entry for Apache to answer on the IP 129.250.242.126 if the servers IP is 129.250.242.125? Are any other changes necessary to get Apache to answer this IP for web traffic? < VirtualHost 129.250.242.126> ServerName www.my_domain.com ServerAdmin admin@my_domain.com... (4 Replies)
Discussion started by: 98_1LE
4 Replies
Login or Register to Ask a Question