Erro Setting up VirtualHost for folders belonging to same domain - apache

Noob Here.. I have the following folder structure on my Ubuntu Machine
/var/www/
/folder1
/folder2
Now i want to redirect my url xyz.com to folder1 & xyz.com/blog to folder2. I am using the following Vhost Config file
For xyz.com to folder1
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName xyz.com
ServerAlias www.xyz.com
DocumentRoot /var/www/folder1
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
.......
</VirtualHost >
And for xyz.com/blog to folder2
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName xyz.com/blog
ServerAlias www.xyz.com/blog
DocumentRoot /var/www/folder2
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
.......
</VirtualHost >
When i enter xyz.com in url, it serves me index file from folder1(As expected & correct) but when i enter xyz.com/blog it shows 404:Not found Error
Not Found
The requested URL /blog/ was not found on this server.
Apache/2.2.22 (Ubuntu) Server at socialcosmo.com Port 80
I have spent hours on this and still unable to figure out the problem :(
Any help would be greatly appreciated

There's no such thing as a host (domain name) with a path in it. xyz.com/blog is not a valid ServerName.
Delete the second virtual host and add an alias directive to your first one.
Alias /blog /var/www/folder2

Related

XAMPP can't see virtual host

I am trying to create virtual host with xampp but it seems my apache configuration can't read host I created.
Every single time when I'm going to moodle36.dev/moodle/install.php in my browser it's reading xampp/htdocs/moodle instead of moodle from vhosts
That's my htttpd-vhosts.conf
NameVirtualHost *80
...
<VirtualHost *:80>
DocumentRoot "C:/xampp/vhosts/moodle36.devel"
ServerName moodle36.dev
ServerAlias www.moodle36.dev
<Directory "C:/xampp/vhosts/moodle36.devel">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
That's httpd.conf
<Directory />
AllowOverride all
Allow from all
</Directory>
DocumentRoot "C:/xampp/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
<Directory "C:/xampp/htdocs">
...
</Directory/>
I uncomented
Include conf/extra/httpd-vhosts.conf
and System32/drivers/etc/hosts
127.0.0.1 moodle36.dev
I'm completly stuck and i would apreciatte any kind of help.
It might be because .dev is an existing top level domain.
Try .localhost or something that isn't in this list:
https://www.icann.org/resources/pages/tlds-2012-02-25-en

How to change port number of Apache server in ubuntu

I want to change my port number 80 to some other number of my Apache server . how it possible in ubuntu
Change your virtal host on any OS, ubuntu path is something like /etc/apache2/apache2 config or something.
#Virtual host for YOURSITE
<VirtualHost *:4343>
ServerAdmin john.doe#jd.com
ServerName webpage.dev #same as in your /etc/hosts file
DocumentRoot /var/www/yoursite
DirectoryIndex index.html
<Directory /var/www/yoursite>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/httpd/yoursite_error.log
#CustomLog /var/log/apache2/customLog.log #for ubuntu
</VirtualHost>
Hope this will help you, you should read about apache coinfiguration...
Here's a great link https://www.digitalocean.com/community/tutorials/how-to-configure-the-apache-web-server-on-an-ubuntu-or-debian-vps
You can create a virtual host configuration file in /etc/apache2/sites-available
Example :--
<VirtualHost *:8080>
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>
. . .
and you have to change Listen port on /etc/apache2/ports.conf
EX:--
Listen 8080

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

XAMPP Windows Apache vhosts not redirecting properly

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
<Directory "C:/xampp/htdocs/">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/gl"
ServerName gl.dev
<Directory "C:/xampp/htdocs/gl">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
The above is what I currently have in my vhosts file. When I hit localhost I want my root to open, but when I load gl.dev I want the individual site to open. Any ideas?
hosts file:
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 gl.dev
I think in windows you have to use backslash when specifying document root. please try the following
<VirtualHost *:80>
ServerName localhost
ServerAlias *.localhost
DocumentRoot "C:\xampp\htdocs\"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName gl.dev
ServerAlias *.gl.dev
DocumentRoot "C:\xampp\htdocs\gl"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Restart WAMP server

2 domains pointing to 1 server (2 different subfolders)

OK, so, I think the title is rather self-explanatory.
I've set up my own Apache server (on Debian) and hosting 2 different sites (let's say mysite1.com at /home/www/mysite1, and mysite2.com at /home/www/mysite2).
In my domain name registrar setup page (Dynadot actually), I created A records (still not sure what this is exactly...) for both of them, pointing to my server's ip...
Now, on the server's side, here'e what my .conf file looks like (/etc/apache2/sites-enabled/mysite actually)
<VirtualHost *:80>
DocumentRoot /home/www/mysite1.com
ServerName www.mysite1.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite1.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin
<Directory "/home/www/mysite1.com/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /home/www/phpmyadmin
ServerName www.mysite1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/www/mysite2.com
ServerName www.mysite2.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite2.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Now, the thing is. Now matter which site I visit (1 or 2), I always get mysite1's contents.
What am I doing wrong? Any ideas?
There are multiple possibilities of what could go wrong.
Do you have
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
somewhere in the config? (http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost)
Without that config entry Apache is not sensitive to domain names in dispatching requests to virtual hosts.
It's just a guess.
Make sure Apache has been reloaded after any changes to the config!