Oscar
Oscar

Reputation: 2335

Why doesn't this Apache virtualhost entry work?

I'm running Apache 2.4.6 on Ubuntu 13.

In sites-available, I have a conf file for my site that contains only this:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email protected]
  ServerName  www.ourco.me
  ServerAlias ourco.me

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/ouruser/public/ourco.me/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/ouruser/public/ourco.me/log/error.log
  CustomLog /home/ouruser/public/ourco.me/log/access.log combined
</VirtualHost>

There are no other conf files enabled. When I have use apachectl -S to display the sites, it shows:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
         port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
                 alias ourco.me
         port 80 namevhost www.ourco.me (/etc/apache2/sites-enabled/ourco.me.conf:1)
                 alias ourco.me
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

The first thing I notice is the duplicate entry for namevhost www.ourco.me. And when I visit the site in a browser, I get:

You don't have permission to access / on this server.

Apache/2.4.6 (Ubuntu) Server at www.ourco.me Port 80

All the directories and files specified in the conf file exist. a2ensite and a2dissite work as expected to add/remove a symlink for this file from sites-enabled, so it's looking at the right file. Does anyone know why its directives are being ignored? Thanks.

Upvotes: 1

Views: 3302

Answers (2)

Oscar
Oscar

Reputation: 2335

This appears to solve the problem:

<Directory />
  Require all granted
</Directory>

when placed in the VirtualHost entry.

That snippet came from this post. I'm looking at this Apache doc to see why it works.

Upvotes: 1

prasoon
prasoon

Reputation: 901

Put Allow from all

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email protected]
  ServerName  www.ourco.me
  ServerAlias ourco.me

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/ouruser/public/ourco.me/public

  # Log file locations
  LogLevel warn
  ErrorLog  /home/ouruser/public/ourco.me/log/error.log
  CustomLog /home/ouruser/public/ourco.me/log/access.log combined
 Allow from all
</VirtualHost>

Upvotes: 1

Related Questions