Apache VirtualHost redirection from different subdomains - apache

I have a DO droplet (Ubuntu 18.04) on which I want to host two sites. Let's say the droplet has an IP of 101.1.1.1. Now I want the sites to be pointed from another server (with different IP, let's say 104.1.1.1.) subdomain. Let's say siteone.example.org and sitetwo.example.org. So I follow the guides and set my Apache VirtualHost like this:
<VirtualHost *:80>
ServerAdmin webmaster#example.org
ServerName siteone.example.org
ServerAlias www.siteone.example.org
DocumentRoot /var/www/siteone/public_html
<Directory /var/www/siteone/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
However, when I press siteone.example.org in my browser I get no response. I've set A name in both to point ends to point to 101.1.1.1. Is there something I'm doing wrong?

You want 2 web sites on the same machine, each with an IP address? So:
configure both IP on your system
Set both IP:80 in Listen
Configure one VirtualHost per IP / domain
Like so:
Listen *.80
<VirtualHost 101.1.1.1:80>
ServerName siteone.example.org
ServerAlias www.siteone.example.org
ServerAdmin webmaster.example.org
DocumentRoot "/var/www/siteone/public/html"
<Directory /var/www/siteone/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/siteone_error.log
CustomLog ${APACHE_LOG_DIR}/siteone_access.log combined
</VirtualHost>
<VirtualHost 104.1.1.1:80>
ServerName sitetwo.example.org
ServerAlias www.sitetwo.example.org
ServerAdmin webmaster.example.org
DocumentRoot "/var/www/sitetwo/public/html"
<Directory /var/www/sitetwo/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/siteotwo_error.log
CustomLog ${APACHE_LOG_DIR}/sitetwo_access.log combined
</VirtualHost>
In your DNS, configure:
101.1.1.1 siteone.example.org www.siteone.example.org
104.1.1.1 sitetwo.example.org www.sitetwo.example.org

Related

Apache Virtual Hosts for Two Sites Not Working Properly

I am trying to have two separate sites with Apache virtual hosts on a test server. I am going to access the sites with the ip address of the instance (for example, http://167.275.122.215). When I enable the following configuration, I would be able to load the first site with just the ip address correctly (with http://167.275.122.215), but not http://167.275.122.215/exp. I get a 404 error when I point to that address. What am I doing wrong here?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
Alias /exp /usr/share/wordpress
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
In fact, my need is to be able to access the exp (experimental) site through the same ip while the main site is still available (from the original ip address). I tried giving a different port to the experimental site too (like below), but that still gave me a site can't be reached error.
<VirtualHost *:90>
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
For port based multiple sites, listing the default port as the second site resolved the issue:
LISTEN 90
<VirtualHost *:90>
DocumentRoot /usr/share/wordpress
<Directory /usr/share/wordpress>
Options FollowSymLinks
AllowOverride all
DirectoryIndex index.php
require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/main
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Multiple Websites on Apache2

I have my apache configured to have 2 websites setup. I have the following in my apache2.conf
Include /opt/bitnami/apps/www.website1.com/conf/app.conf
Include /opt/bitnami/apps/www.website2.com/conf/app.conf
Here are the app.conf for the 2 websites
Website1
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName www.website1.com:80
ServerAlias website1.com
ErrorLog /opt/bitnami/apps/www.website1.com/log/error.log
CustomLog /opt/bitnami/apps/www.website1.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website1.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName website1.uat.com:80
ServerAlias website1.uat.com
ErrorLog /opt/bitnami/apps/www.website1.com/log/error.log
CustomLog /opt/bitnami/apps/www.website1.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website1.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Website 2
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website2.com/htdocs
ServerName www.website2.com:80
ServerAlias www.website2.com
ErrorLog /opt/bitnami/apps/www.website2.com/log/error.log
CustomLog /opt/bitnami/apps/www.website2.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website2.com/htdocs">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.website2.com/htdocs
ServerName website2.com:80
ServerAlias website2.com
ErrorLog /opt/bitnami/apps/www.website2.com/log/error.log
CustomLog /opt/bitnami/apps/www.website2.com/log/access.log common
<Directory "/opt/bitnami/apps/www.website2.com/htdocs">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Im testing these locally so i have my host setup below
xx.xxx.xx.xxx www.website1.com
xx.xxx.xx.xxx www.website2.com
When i go to www.website2.com, apache2 page pops up
When i go to www.website1.com, apache2 page pops up
When i go to www.website2.com/htdocs, i see the correct website and it works. When i got to www.website1.com/htdocs, i see website2. I dont understand why i am seeing website 2 here.
My first guess would be that you should remove the port :80 from ServerName and also change
<VirtualHost *>
to
<VirtualHost *:80>
Like so:
<VirtualHost *:80>
DocumentRoot /opt/bitnami/apps/www.website1.com/htdocs
ServerName www.website1.com
...
As prerik says use "VirtualHost *:80"
Also if it is Apache HTTPD 2.2.x, it needs "NamedVirtualHosts *:80" defined "once" in the config when several virtualhosts are present using the same ip:port scheme, if you don't add this all your requests will land in the first defined virtualhost.

apache virtual host not working for laravel app on digitalocean IP

I have create virtual host, but not working I am using digitalocean IP
<VirtualHost *:80>
ServerName ip/laravelblog
ServerAlias www.ip/laravelblog
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravelblog/public
#/etc/apache2/sites-available/laravelbog.conf
<Directory /var/www/html/laravelblog/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
000-default.conf is also enabled and laravelblog also.
my url is ip/laravelblog ( I am using digitalocean IP). when I access my url (ip/laravelblog). its show all laravel folder. I need to point direct public folder.
I have solved the problem.
<VirtualHost *:80>
#ServerName
ServerAlias IP
Alias /project1 /var/www/html/project-path/public
Alias /project2 /var/www/html/project-path/public
DocumentRoot /var/www/html
<Directory "/var/www/html/>
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
the url will be IP/project1
for other project IP/project2
So you can add more and more Alias on one IP

Multiple Aliases for Multiple vhosts httpd

I want any domain to point a CNAME on my vhosts for that i use
ServerAlias *
in my vhosts but it only works with one vhost if I add it in both the CNAME pointed to the second vhost serves the contented from the first vhost.
e.g:
1st: files.domain.com CNAME to files.example.com
2nd: r.domain.com CNAME to r.example.com
but second one is also serving files.example.com
My httpd.conf has these two vhosts
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/files.example.com
ServerName files.example.com
ErrorLog /var/www/files.example.com/logs/error_log
CustomLog /var/www/files.example.com/logs/custom_log common
<Directory "/var/www/files.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/r.example.com
ServerName r.example.com
ErrorLog /var/www/r.example.com/logs/error_log
CustomLog /var/www/r.example.com/logs/custom_log common
<Directory "/var/www/r.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This may not be directly related but it could be of help to others: you can actually put many aliases in the same virtual host entry (in my case for the same domain):
ServerName example.com
ServerAlias mail.example.com files.example.com r.example.com
And be sure to include all these as server-aliases also while creating an SSL Certificate for the domain.
You have to add ServerAlias lines
below ServerName files.example.com add ServerAlias files.domain.com
and below ServerName r.example.com add ServerAlias r.domain.com
In your case apache uses files.example.com as default vhost, because it is first one.
I solved this problem by setting a dedicated ip on the vhost where I want the ServerAlias to be * and it worked
<VirtualHost 192.168.1.55:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/r.example.com
ServerName r.example.com
ServerAlias *
ErrorLog /var/www/r.example.com/logs/error_log
CustomLog /var/www/r.example.com/logs/custom_log common
<Directory "/var/www/r.example.com">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

VirtualHost configuration issue

I have two apps I want to serve via port 80 in Apache on the same ip host. To do so, I have defined the following virtual hosts:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/wsgi/rest_api"
ServerName api
WSGIDaemonProcess rest_api user=gms threads=5
WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
WSGIPassAuthorization On
<Directory /var/www/wsgi/rest_api/rest_api>
Order deny,allow
Allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/extjs/cardiocatalogqt"
ServerName cardiocatalogqt
Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
<Directory /var/www/extjs/cardiocatalogqt>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
The problem is that only the first one in the list is being recognized (they both work independently). What am I missing to get both of these working together, independent of order?
EDIT
I am trying to avoid use of different server names due to a CORS authentication issue across domains (which includes host names and ports). All I want is two different paths as such to resolve accordingly: http://test.com/cardiocatalogqt and http://test.com/api.
Please create two different virtual host with different server names and different document root paths
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Also, add the server name into the hosts file.
mod_alias was what I wanted, ala http://httpd.apache.org/docs/2.2/mod/mod_alias.html
Works like a charm!
EDIT
More specifically, my config looks like this:
WSGIDaemonProcess rest_api user=gms threads=5
WSGIScriptAlias /api /var/www/wsgi/rest_api/rest_api.wsgi
WSGIPassAuthorization On
<Directory /var/www/wsgi/rest_api/rest_api>
Order deny,allow
Allow from all
Options +Indexes
</Directory>
<VirtualHost *:80>
DocumentRoot "/var/www/extjs/cardiocatalogqt"
ServerName cardiocatalogqt
Alias /cardiocatalogqt /var/www/extjs/cardiocatalogqt
<Directory /var/www/extjs/cardiocatalogqt>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>