Problems with Apache Virtual Host

I am attempting to add virtual hosts to an apache web server, which has this current configuration:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                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 ${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>

I have been trying to add a configuration like this, based off another working server:

<VirtualHost *:80>
        ServerName subname.servername.com
        DocumentRoot /path/to/new/documentroot
</VirtualHost>

...but it totally ignores the new configuration, going straight to /var/www in defiance of the new virtualhost whenever subname.servername.com is accessed. So I get the 'it works!' page, instead of someone's particular wordpress instance.

I can tell it's at least reading the configuration though, since adding the virtualhost somehow breaks apache's ability to follow symbolic links.

What might I be doing wrong?

Hi.

Which OS / version of Apache are you using?

Did you enable the NameVirtualHost directive? Is there a hosts/DNS entry for the new virtual host?

I tried lots and lots of things, including NameVirtualHost in various combinations.

The system is Ubuntu. I am trying to find the apache version.

If I add "NameVirtualHost *:80" to the top, apache2 will complain "NameVirtualHost *:80 has no VirtualHosts" in defiance of the default virtual host and however many virtual hosts I add.

As for hosts/DNS entry, whatevername.mywebsite.com already works, the site can tell what name you call it with. Except that virtual hosting does not work.

its simple:

  1. nano /etc/apache2/sites-available/mynewdomain.com
  2. enter following

3.Save the file
4.Add the new site with the following command

5.Restart apache

you can read more here: newexception.com/apache-virtual-host

Does not work.

Does the exact same thing as described above, the exact same way as described above: Sites continue going to /var/www despite the virtualhost telling them to go somewhere else.

I even have the 'NameVirtualHost *:80 has no VirtualHosts' error despite having obvious virtualhosts, just like described above.

Any further thoughts?

is this linux box your home pc? or a vps/dedicated server?

did u tried to add the domain in /etc/hosts?
read the article

Adding 127.0.0.1 to /etc/hosts would be counterproductive since I want to access this site from the server's main address -- the server really does have a working domain name, and I am accessing it from the outside. I will attempt adding the real IP to /etc/hosts...

It is a home server, and not any sort of VPS.

[edit] Adding the IP to /etc/hosts made no difference.

[edit] Just for laughs, I tried 127.0.0.1 in /etc/hosts too. It didn't make any difference.

I am trying to get access to the domain name to verify it has the right settings.

remove that * and replace with localhost in default conf file and then add vhost entry

Example:

<VirtualHost sitetest:80>
    ServerName sitetest
    DocumentRoot ...
    ErrorLog ...
    CustomLog  ...
</VirtualHost>

and in /etc/hosts add entry of sitename

restart apache

What is "sitetest" supposed to be?

Does not work.

I now get the "NameVirtualHost *:80 has no VirtualHosts" error twice.

[edit] Removing the "NameVirtualHost" directive has it now working. THANK YOU!

if your site is sitetest.com then <VirtualHost sitetest:80> I mean

so, sitetest:80, not sitetest.com:80 ?

Yup! missed exactly because of copy paste it happened :), I mean to say servername

Well it does not work unless I put sitetest.com, not just sitetest.

It still complains that NameVirtualHost *:80 has no virtualhosts, and nothing but my first vhost works, so I suspect I haven't gotten vhosting working -- just broken my default vhost, to force it to use mine instead.

$ pwd
/etc/apache2/sites-enabled
akshay@Aix:/etc/apache2/sites-enabled$ ll 
total 8
drwxr-xr-x 2 root root 4096 Nov 12 18:53 ./
drwxr-xr-x 7 root root 4096 Nov 12 18:53 ../
lrwxrwxrwx 1 root root   26 Nov 12 18:53 000-default -> ../sites-available/default

Did you replace VirtualHost *:80 with VirtualHost localhost:80 in sites-available/default ? and added vhost ?

I removed all NameVirtualHosts from my virtualhosts. There appears to be one in the /etc/apache2/ports.conf however. Should I edit it there?

[edit] Edited there. No difference.

Whenever I try to subdomain my site I get warnings like

[Mon Jan 20 10:46:38 2014] [warn] VirtualHost lmcmg.mysite.com:80 overlaps with VirtualHost mysite.com:80, the first has precedence, perhaps you need a NameVirtualHost directive

...but adding a NameVirtualHost does not help. Sometimes I can get it to stop printing the warning, but it still overrides everything, not just the URLs I wanted.

I edited previous post please see.

Let me explain my exact situation.

I have wordpress installed in /usr/share/wordpress, shared. I also have a few user-modifiable directories in /srv/www/wp-content/lmgmg.sitename.com/uploads and so forth.

I am hoping to be able to define mysite.com with a documentroot of /usr/share/wordpress, and alias /wp-content/uploads into the various /srv/www/wp-content/site/uploads directories individually. So far, I can't alias /wp-contents/uploads individually, only globally.

OK, let me show you exactly what I have right now:

/etc/apache2/sites-enabled/default:

NameVirtualHost localhost:80

<VirtualHost localhost:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                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 ${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>

/etc/apache2/sites-enabled/mysite.com:

<VirtualHost mysite.com:80>
        ServerName mysite.com
        DocumentRoot /usr/share/wordpress
        alias /wp-content/uploads /srv/www/wp-content/lmcmg.lakeshoremed.ca/uploads
</VirtualHost>

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

Every other apache configuration file has been left at ubuntu defaults.

When I start apache with this exact configuration I get these warnings:

# /etc/init.d/apache2 restart * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Mon Jan 20 11:10:17 2014] [warn] VirtualHost lmcmg.mysite.com:80 overlaps with VirtualHost mysite.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Mon Jan 20 11:10:17 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
 ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Mon Jan 20 11:10:18 2014] [warn] VirtualHost lmcmg.mysite.com:80 overlaps with VirtualHost mysite.com:80, the first has precedence, perhaps you need a NameVirtualHost directive
[Mon Jan 20 11:10:18 2014] [warn] NameVirtualHost *:80 has no VirtualHosts
                                                                         [ OK ]
#

I get /wp-content/uploads overrided for every subdomain inside mysite.com, not just lmcmg.

I did not read the entire thread, but normally with apache, each virtual host is defined in it's on file in the directory:

/etc/apache2/sites-available

Then you make a symlink to the file(s) in that directory from:

/etc/apache2/sites-enabled

When I read (maybe too quickly) though the thread, it seems you were trying to create a new virtual host with the configuration file of an existing virtual host. If that's not the case, I apologize; as I only quickly glanced over the thread.

For example,

/etc/apache2/sites-available/my.great.site.com
/etc/apache2/sites-available/my-other.great.site.com

Then you symlink to these files, something like:

/etc/apache2/sites-enabled/site1 -> ../sites-available/my.great.site.com
/etc/apache2/sites-enabled/site2 -> ../sites-available/my-other.great.site.com

There are apache2 commands to do this for you.

Then restart of course. ( service apache2 restart )

Each virtual host we keep in a separate file... I have one apache2 server with 15 sites like this.

Hope this helps.

Hm. I'll try splitting that one with two vhosts.