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>
Related
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
I currently have one domain set up on my LAMP server, and I want to add another one. I tried doing it myself but when I ran into issues, I follow this. I had example.com set up and it was working fine, all traffic would redirect to its https and I want to continue that.
However, the second domain I'm using (represented by test.ca) is still going to example.com. I was hoping someone could inform me what I am doing wrong. Should test.ca be a folder within example.com? and how do you point to it? Is it cause I redirect traffic to https://example.com for the ssl so all traffic just goes there?
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example#gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin example#gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example#gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/test.ca.conf
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:444>
ServerAdmin example#gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
You might want to change the header of the Virtualhost from
<VirtualHost *:444>
to
<VirtualHost *:443>
as a start, or it must be your intentions to link to that port instead of the default https port.
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>
If I go for http://example.com then its pointing to /var/www/html
Now I am in need that if I go for http://example.com/dashboard then it will point to /var/www/example/public. Or If this not possible then /var/www/html/example/public would also be okay.
And again I need that if I go for http://wildcardsubdomain.example.com/ then also it will point to /var/www/example/public. Or If this not possible then /var/www/html/example/public would also be okay.
How can I make so?
I have tried with this but /dashboard not working:
ServerName example.com
# Listen for virtual host requests on all IP addresses
UseCanonicalName Off
#dynamic subdomain provisioning
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
#WORKING
ServerName user.example.com
ServerAlias *.example.com
DocumentRoot /var/www/example/public
</VirtualHost>
<VirtualHost *:80>
#NOT WORKING
ServerName www.example.com/dashboard
ServerAlias *.example.com/dashboard
DocumentRoot /var/www/example/public
</VirtualHost>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
For dashboard I could solve that using the Alias Directive
<VirtualHost *:80>
DocumentRoot /var/www/html
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
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>