Linux virtualhost subdirectories not working - apache

I can only access 1 website '/resume/', sub directory websites are not visible externally? The site '/resume2/' tries to point to /resume/. All the sub sites are trying to point to /resume/
<VirtualHost *:80>
ServerName resume
ServerAlias resume
DocumentRoot "/var/www/html/resume/"
<Directory /var/www/html/resume/>
DirectoryIndex index.php phpinfo.php index.html index.htm
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName resume2
ServerAlias resume2
DocumentRoot "/var/www/html/resume2/"
<Directory /var/www/html/resume2/>
DirectoryIndex index.php phpinfo.php index.html index.htm
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

I'm pretty sure you should define different hostnames/IPs or port behind the VirtualHost tag, e.g.
<VirtualHost resume.mydomain.de:80>
ServerAlias resume
ServerName resume.mydomain.de
DocumentRoot "/var/www/html/resume/"
...
</VirtualHost>
<VirtualHost resume2.mydomain.de:80>
ServerAlias resume
ServerName resume.mydomain.de
DocumentRoot "/var/www/html/resume2/"
...
</VirtualHost>
... where resume.mydomain.de and resume2.mydomain.de are resolved to two different IP that are both configured on your host. You could also use the same IP and different port. Anyhow, keep in mind that you need to add a listen tag to your configuration for each VirtualHost.
Hope that helps! Cheers ...

Related

Wildcard subdomain not using correct conf file

I have a set up as follows:
All subdomains pointing to the server
sub1.example.com should load /var/www/sub1
sub2.example.com should load /var/www/sub2
Any random subdomain should load /var/www/shared
The problem is the shared.conf file is being ignored and instead using sub1 (or whichever one I move to the start of the .conf file list).
Here are my conf files in their order after running ls -lv
sub1.conf
sub2.conf
shared.conf
sub1.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub1.example.com
ServerAlias sub1.example.com
<Directory /var/www/sub1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub1
</VirtualHost>
sub2.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub2.example.com
ServerAlias sub2.example.com
<Directory /var/www/sub2/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub2
</VirtualHost>
shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias *.example.com
<Directory /var/www/shared/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/shared
</VirtualHost>
I have also tried adding a random subdomain to the shared.conf file for Server Name, i.e.
ServerName shared-random.example.com
And also
ServerName *.example.com
I have also made sure to restart apache.
So when I put in any subdomain, e.g. blabla.example.com it always goes to sub1.conf.
I understand that the behaviour is to default to the first one, but only if there isnt a match. Why isnt shared.conf being considered a match?
change filename from shared.conf to 000-shared.conf
use below config for 000-shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/shared
<Directory /var/www/shared>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
</VirtualHost>

Apache2 subdomain redirects to main domain

I have an EC2 instance setup running Ubuntu 14.04 and Apache. I have a single elastic IP serving multiple domains and subdomains all of which point to individual folders on the server. The problem I am having is unless the subdomain is explicitly set in my .conf it will redirect to the main domain. I can't seem to find a definitive answer here or in google.
I have a single .conf file residing in /etc/apache2/sites-enabled/ serving all of the domains and subdomains like so:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain.com
<Directory /var/www/html/mydomain.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub1.mydomian.com
ServerAlias www.sub1.mydomain.com
DocumentRoot /var/www/html/sub1.com
<Directory /var/www/html/sub1.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub2.mydomian.com
ServerAlias www.sub2.mydomain.com
DocumentRoot /var/www/html/sub2.com
<Directory /var/www/html/sub2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain2.com
ServerAlias www.mydomain2.com
DocumentRoot /var/www/html/mydomain2.com
<Directory /var/www/html/mydomain2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
So if I go to sub1.mydomain.com or sub2.mydomain.com it gets properly routed. But if I type sub3.mydomain.com which does not exist in my .conf file it gets redirected to mydomain.com. I do not want this behavior. How do I resolve this?
You need to enable name based virtualhosts. Add below line before your first virtual host and restart apache.
NameVirtualHost :80

Apache vhost not working for subdomains

I have this configuration but both url app.test.com & stage.test.com
redirect to same code/deployment
<VirtualHost *:80>
ServerName app.test.com
DocumentRoot /var/www/html/Test-Prod/web
<Directory "/var/www/html/Test-Prod/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-prod__error_log
CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName stage.test.com
DocumentRoot /var/www/html/Test/web
<Directory "/var/www/html/Test/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-website_error_log
CustomLog logs/test-website_access_log common
</VirtualHost>
The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2
Add the following in your config file and it'll probably work
NameVirtualHost *.80
You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2.
NameVirtualHost *.80
<VirtualHost localhost:80>
ServerName color
ServerAlias localhost
ServerPath "C:/wamp/www/subwww/color"
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www/subwww/color">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
in above code, subdomain name is color
and the url is http://color.localhost/
if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration

Add a sudomain for each folder in my userdir path with Apache

I activated the userdir mod with apache2 and configure my domain to get the content of the www folder in my home.
I create a Virtualhost for the main domain which works good.
But now i would like to automatically add a subdomain for each folder in my /home/user/www/
Here is the virtualhost i code, but it redirect all the subdomains to the /home/user/www/
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
ServerAlias *.mysite.com
DocumentRoot /home/user/www/
UseCanonicalName Off
VirtualDocumentRoot /home/user/www/%1
<Directory /home/user/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.mysite.log
LogLevel warn
CustomLog /var/log/apache2.mysite.log combined
</VirtualHost>`
Try changing:
VirtualDocumentRoot /home/user/www/%1
to:
VirtualDocumentRoot /home/user/www/%0
You can read more about this feature at mod_vhost_alias.

Using a directory in VirtualHost ServerName

I'm currently using name-based virtual host configuration, to server about 5 different websites from the same IP address, just like in the apache documentation:
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
Is it possbile to have something like:
<VirtualHost *:80>
ServerName www.domain.tld/folderpath
DocumentRoot /www/software
</VirtualHost>
The webpages in this folder are using a different software stack, and I'd like to keep it nicely separate. I tried the method above but it didn't work.
It's not possible the way you show - a VirtualHost is always just a host. But you could use an Alias.
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
Alias /folderpath /www/software
</VirtualHost>
Is it possible to have a different vhost for each application like that:
<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain.tld
Alias otherApp /www/otherApp
</VirtualHost>
I add to the alias.conf file (on a windows machine).
Remember that if it outside the 'document root' path, you'll need permissions
<IfModule alias_module>
#### FolderPath ####
Alias /folderpath "E:/any/path/you/like"
<Directory "E:/any/path/you/like">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#### Another ####
Alias /another "E:/another/different/path"
<Directory "E:/another/different/path">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</IfModule>