Apache - Hyphen in ServerName breaks VirtualHost - apache

I can't get Apache's configuration to return the correct page, if there is a hyphen in the ServerName. I found a page here titled, "Dashes not allowed in virtual host entry?", but it was dealing with hyphens in the DocumentRoot, not with ServerName. In any case, it did not solve my problem, and I've been unable to find any other references to this problem.
I'm setting up multiple virtual hosts (VH) on a recently acquired Ubuntu 12.04 server, running Apache. Ubuntu's configuration for this is organized so that you have folders for sites-available and sites-enabled. A separate file, placed in sites-availabe is used for each individual VH. Enabling the VH is just a matter of making a symlink from the file in the sites-available folder to the sites-enabled folder, and restarting Apache.
I have several working VHs already. It's an easy recipe, since it's just a matter of copying a working file to a new filename, and changing a few variables.
All of my correctly-working entries do NOT have any hyphen in the ServerName, or ServerAlias. The one entry which does have a hyphen, does not work. Instead of returning the proper page, Apache returns the host's base page (which tells me DNS is fine).
I've tried enclosing ServerName and ServerAlias in quotes, with and without. No change.
Lots of domains use hyphens, I can't be the only one with this problem. Has anyone found a workaround? Here's my config:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName datacore-inc.com
ServerAlias www.datacore-inc.com
DocumentRoot /home/web/datacore/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/web/datacore/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

I had the same issue and thought the problem came from the hyphen character in the ServerName. But actually I had declared the VirtualHost twice. I've removed one of them and that resolved the problem.

Related

Apache showing empty "index of /", after dist upgrade

I'm working on a Debian 7 server which I did a dist upgrade on so it is Debian 8 now.
The only thing I am having trouble with is the apache2 which got updated from 2.2 to 2.4. the problem that is that now it shows me an empty "Index of /" although there are a lot of files in the specified folders.
vHost Conf:
<VirtualHost *:80>
ServerAdmin some#email
ServerName some.server
ServerAlias some.server
DocumentRoot "/data/apt/public_html"
<Directory "/data/apt/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
</VirtualHost>
How can I get it working again?
mixing 2.2 and 2.4 access directives is not recommended. Look at http://httpd.apache.org/docs/current/upgrading.html. You will see that they never mix Order allow,deny with Require all granted. So remove your Order line.
Mixing old and new directives
Mixing old directives like Order, Allow or Deny with new ones like
Require is technically possible but discouraged. mod_access_compat was
created to support configurations containing only old directives to
facilitate the 2.4 upgrade. Please check the examples below to get a
better idea about issues that might arise.
Also, you do not specify a DocumentIndex file so Apache does not know which file it should return a client when he asks for http://some.server/.
Let's assume the default page is index.html, add this in your VirtualHost:
DocumentIndex index.html
Note 1: ServerAlias has the same value as ServerName, and is therefore not required.
Note 2: you should setup access and error log files for this VirtualHost. It might not be useful if you have only 1 VirtualHost, but you will thank me if you have a large site (with multiple VH later).

Apache2 Alias Prerequisites

I have four Web development systems, two with Windows 10 and two with Ubuntu Linux and have set up Alias folders on three without a problem but am currently traveling and having trouble with the fourth. It is running Ubuntu with Apache2. A sample of one of the VirtualHost entries is below.
<VirtualHost devsite.dev:80>
DocumentRoot /var/www/html/devsite.dev
ServerName devsite.dev
Alias /common/ /var/www/html/devsite.dev/common/
<Directory "/var/www/html/devsite.dev">
AllowOverride None
Options FollowSymLinks Indexes
Require all granted
</Directory>
Options FollowSymLinks
</VirtualHost>
The above does not work so what did I miss? All site folders including the common folder are in /var/www/html/ and I must have missed something as the alias is not working. In other words, each site has its own sitename.dev folder so http://devsite.dev/ pulls up the site but there is no physical folder within the site folder for http://devsite.dev/common/ to work so needs an Alias. Not sure if trailing slashes are needed or not and can't recall what my other systems have but either way it doesn't seem matter here.
When I say it doesn't work, I mean that the aliased folder does not show up in the PC's file manager as it does on all my other systems and the site cannot find it using the browser in order to load files from it as I showed above in the sample URLs.
Perhaps I was not too clear that common is not within /var/www/html/devsite.dev. Instead it is at /var/www/html/common and it does require an Alias to work. Also, there is already a DocumentRoot /var/www/html line in the Apache 000-default.conf file.
I was under the mistaken impression that the Alias path was telling the system where the alias should appear but I was obviously wrong so here's the answer for others to see. Still not sure of the trailing slashes but, as it is working with them, I'll leave them in.
<VirtualHost devsite.dev:80>
DocumentRoot /var/www/html/devsite.dev
ServerName devsite.dev
Alias /common/ /var/www/html/common/
<Directory "/var/www/html/devsite.dev">
AllowOverride None
Options FollowSymLinks Indexes
Require all granted
</Directory>
Options FollowSymLinks
</VirtualHost>

Windows 10, MAMP virtual host setup doesn't work

I've went through all the posts I could find here, still couldn't get this to work:
I Have a Windows 10 + MAMP.
MAMP is set to folder C:/MAMP/htdocs as the root folder
I un-commented the Virtual host line on the httpd.conf:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Added :
<VirtualHost *:80>
DocumentRoot "C:/MAMP/htdocs/team/example"
ServerName dev.example.com
ServerAlias dev.examplecom
</VirtualHost>
into httpds-vhosts.conf to the extra folder (under conf)
added the following to my hosts file:
127.0.0.1 dev.example.com
I Can get to localhost,
But every time I try a domain, it gices me: Not Found (The requested URL / was not found on this server.)
I'm pretty sure I am missing something small, But will greatly appreciate a solution to this.
So far i tried changing the Path in the conf files.
Tried using relative paths rather than absolute.
Tried any idea I could find onlie,
Thanks, and a happy new year :)
Cheers.
Changing the line from Include conf/extra/httpd-vhosts.conf to Include C:/MAMP/conf/extra/httpd-vhosts.conf worked for me.
It seems that httpd.conf requires absolute paths
I didn't see you mention anything about SymLink, maybe that's what you're missing to make it work.
Find this line in that same C:\MAMP\conf\apache\httpd.conf file.
<Directory />
Options FollowSymLinks ExecCGI
AllowOverride none
Order deny,allow
Allow from all
</Directory>
Change AllowOverride from none to all
<Directory />
Options FollowSymLinks ExecCGI
AllowOverride all
Order deny,allow
Allow from all
</Directory>
Although I'm late to the party, hope that helps.
Also make sure to restart the servers on MAMP after making any changes! If you don't reset the server to apply the changes, nothing will work even though you know you've done everything right.
Not sure if this question is still relevant but I was having the exact same problem setting up my Virtual Host recently and I was receiving the: Not Found (The requested URL / was not found on this server.). The solution for me was to write it as the following:
<VirtualHost *:80>
DocumentRoot C:/MAMP/htdocs/team/example
ServerName dev.example.com
ServerAlias dev.examplecom
</VirtualHost>
Without the quotations around the DocumentRoot. Seems both simple and dumb but it worked for me. Make sure to restart the Mamp Servers again!
I don't have enough points to comment on James's answer, but this is another quirk of the Windows environment:
In the hosts file, Windows wants two lines for each virtual host:
127.0.0.1 dev.example.com
::1 dev.example.com

Setting root directory in a development environment

I have a linux server that I do all of my web development on. I cant find an example of a virtual host.
I need a way to set virtual hosts (i think) so that even when i am running http://dev.example.com/blah i need that URL to be treated as a different site.
I know that i cannot use sub domains because to access the server I have to navigate through a sub domain.
If you need any clarifications please ask.
Virtual hosts are set using a <VirtualHost> section in apache configuration file(s) generally being httpd.conf,apache2.conf.It looks like
<VirtualHost *:80>
ServerAdmin webmaster#dev.example.com
ServerName dev.example.com
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>
</VirtualHost>
You can change DocumentRoot as per your convenience.
In few versions of distros such different sections of main trivial configuration file httpd.conf are segregated to separate files.
For example apache2 on latest ubuntu has separate files per virtual host located at /etc/apache2/sites-enabled/
You may find 000-default already in this directory which sets the default host(localhost)
You may copy it and start editing to define a new virtual host.With above snippet you will be configuring new host. Key point is setting DocumentRoot to a different directory for dev.example.com to configure as a different site.
I assume your dev machine is able to resolve what is set for ServerName else you may want to configure it too in /etc/hosts on debian based linux.

Apache Stopped Following Symlinks

Yesterday, I had a fistful of sites running locally with no problem. Today, nothing opens and I have a log full of this:
Symbolic link not allowed or link target not accessible: /var/www
I have no idea what I did (I didn't open/change my httpd.conf file in any way), but clearly it was something bad. I run virtual hosts and the root directories are located in ~/Developer/www. In order to share the config files across multiple Macs with different home directories, I've created a symlink, /var/www which points to ~/Developer/www.
All of the virtualhost config files point their DocumentRoot to /var/www/project_directory and its own root directory has the FollowSymLinks option:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost.local localhost.dev
DocumentRoot /var/www/_localhost
<Directory /var/www/_localhost>
Options FollowSymLinks Indexes
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
My main httpd.conf file, similarly, has the FollowSymLinks option enabled for /:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Any idea what I could have done to stop Apache from understanding symlinks or, better yet, what I can do to get it back on track?
Thanks.
UPDATE:
I should add that all of the directories in the "stack" are executable by all users and that this is the native Apache install on OS X Lion.
I guess I made an assumption that I shouldn't have. I had verified every relevant permission except the one that evidently mattered. Apache didn't have execute permissions on my top level home directory. I checked, re-checked and triple checked everything under that, but having never changed anything in that directory itself, I just didn't anticipate it being the issue.