I have searched far and wide for this answer, and can't find a working solution. So here goes,
I have 2 VirtualHosts set up on my server, with each serving a separate domain name. However, when I visit the first domain on the list, it then serves the DocumentRoot of the second domain. I even have them both listening on different ports. In my DNS under each domain I've got them leading to the IP of the server.
Here is my Apache .conf file:
ServerName 137.117.33.226
<VirtualHost *:443>
ServerName joshstroup.me
ServerAlias www.joshstroup.me
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/joshstroup.me.cert
SSLCertificateKeyFile /etc/apache2/ssl/joshstroup.me.key
</VirtualHost>
<VirtualHost *:80>
ServerName respice.xyz
ServerAlias www.respice.xyz
DocumentRoot /var/www/respice
</VirtualHost>
Related
I'm having some problems configuring multiple domains in my apache instance.
I have 2 domains: a.com and b.com
I only want to configure the cert files once, so i have a configuration for a.com and b.com. But if i have something like this:
<VirtualHost *:443>
ServerName a.com
ServerAlias www.a.com *.a.com
SSLEngine On
SSLCertificateFile /path/fullchain-a.pem
SSLCertificateKeyFile /path/privkey-a.pem
</VirtualHost>
<VirtualHost *:443>
ServerName b.com
ServerAlias www.b.com *.b.com
SSLEngine On
SSLCertificateFile /path/fullchain-b.pem
SSLCertificateKeyFile /path/privkey-b.pem
</VirtualHost>
it wont allow me to define subdomains in seperate configuration files. Because of the whole wildcard stuff, it just doesn't care about the following vhosts.
Is there a way to configure the certificates centrally so all subdomain vhosts will automatically default to them, without having to specify the whole path in each and every subdomain config?
So i just need to do this:
<VirtualHost *:443>
ServerName subdomain.b.com
DocumentRoot /var/www/html-b
</VirtualHost>
<VirtualHost *:443>
ServerName subdomain.a.com
DocumentRoot /var/www/html-a
</VirtualHost>
<VirtualHost *:443>
ServerName test.a.com
ServerAlias test.b.com
DocumentRoot /var/www/shared-html
</VirtualHost>
or do i need to specify the certificate paths for each subdomain?
I tried using multiple default vhosts, but it would always default to the fist one.
I'm trying to configure Apache with three different VirtualHosts, such that a specific VirtualHost will be used when someone requests either the corresponding subdomain (e.g. foo.example.com) or the corresponding subfolder (e.g. example.com/foo).
I thought the following httpd.conf would do the trick, but the ServerAlias directives are simply being ignored:
<VirtualHost *:80 *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /srv/http
</VirtualHost>
<VirtualHost *:80 *:443>
ServerName foo.example.com
ServerAlias example.com/foo
DocumentRoot /usr/share/web
</VirtualHost>
<VirtualHost *:80 *:443>
ServerName bar.example.com
ServerAlias example.com/bar
DocumentRoot /var/www/html
</VirtualHost>
When bar.example.com is requested the third VirtualHost is used, as intended. However, in the case of example.com/bar the first VirtualHost takes precedence despite the ServerAlias. Similarly, requesting example.com/foo matches the first VirtualHost, not the second.
How can I fix this configuration to produce the desired behavior?
ServerAlias takes a hostname, not a hostname and a path. This mechanism doesn't do what you want it to do. Just create an Alias or Redirect in the virtual host being accessed.
i'm try to setup multiple wordpress sites on my Amazon EC2 instance. Here's how my httpd.conf file looks like:
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /var/www/html/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.co
ServerAlias domain2.co
DocumentRoot /var/www/html/domain2
</VirtualHost>
So, when i entered domain1.com or www.domain1.com in the browser, it redirects correctly to the content i wanted and so does www.domain2.co . However, when i entered domain2.co, it doesn't directs to the ServerName www.domain2.co but to the first VirtualHost settings www.domain1.com.
Anything i'm missing out here?
Try this. Apache will default to the 1st virtual host if it doesn't find a virtualhost match which means your second VirtualHost is being ignored. We use www. as an alias and the domain as the server name. See if this helps.
<VirtualHost *:80>
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/html/domain1
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/html/domain2
</VirtualHost>
Figured it out guys, the browser caches previous data when domain2.co points to domain1.com. So even when i have set the virtualhost correctly for domain2.co, the browser will still load the previous cached data from domain1.com.
Solution will be to clear browser data.
Found out that another factor affecting this could be because of your ISP.
Read more here: https://sg.godaddy.com/help/what-factors-affect-dns-propagation-time-1746
I need all url mydomain.com, a.mydomain.com, b.mydomain.com, whatever.mydomain.com....
point to the same DocumentRoot, the subdomain is dynamic(maybe have more than hundreds)
Now I have the following lines in 000-default.conf:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias *.mydomain.com
The mydomain.com is work, but all subdomain is not found.
Can someone help me? thanks so much.....
For example:
A user register a new account, the new account is "obama" then the url would be "obama.mydoamin.com". The subdomain can be entry when the account create immediately.
Wildcard sub-domains are possible using Apache virtual hosts.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName xyz1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/wildcard
ServerName other.example.com
ServerAlias *.example.com
</VirtualHost>
The first entry will become the default if you don't get an explicit match. So if you had xyz.otherexample.com point to it, it would be caught be xyz1.example.com. You need to turn on the name based virtual hosts with the first entry.
For further details you can also refers to apache documentation apache Doc
I have a CentOS/Apache+OpenSSL server. I host two domain names with wildcard sub domains (application logic surfaces the correct site), e.g.
https://*.testing1.com
https://*.testing2.com
It works great over HTTP:-
<VirtualHost *:80>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin webmaster#testing1.com
ServerName testing1.com
ServerName testing2.com
ServerAlias *.testing1.com *.testing2.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/app/public_html/public
</VirtualHost>
I've purchased two Wildcard SSL certificated for both testing1.com and testing2.com, but I'm unsure how to set it up in this structure:-
<VirtualHost *.testing1.com:443>
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/*.testing1.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/*.testing1.com.key
SSLCACertificateFile /etc/httpd/ssl/geotrust.cer
ServerAdmin john#testing1.com
ServerName testing1.com
ServerAlias *.testing1.com
DirectoryIndex index.html index.php
DocumentRoot /home/app/public_html/public
</VirtualHost>
<VirtualHost *.testing2.com:443>
SSLEngine On
SSLCertificateFile /etc/httpd/ssl/*.testing2.com.crt
SSLCertificateKeyFile /etc/httpd/ssl/*.testing2.com.key
SSLCACertificateFile /etc/httpd/ssl/geotrust.cer
ServerAdmin john#testing2.com
ServerName testing2.com
ServerAlias *.testing2.com
DirectoryIndex index.html index.php
DocumentRoot /home/app/public_html/public
</VirtualHost>
The above for the SSL doesn't work, with the *.testing1.com definition, nor with just testing1.com.
I will also need to repeat this for testing2.com
Name-based virtualhosts and SSL wil only work if all the virtualhosts are within the same domain and you have a wildcard SSL certificate for that domain.
But you have 2 different domains.
In this case it will only work if you give each SSL-enabled virtualhost it's own IPaddress.
So you should use IP-based virtualhosts, not Name-based.
Explanation:
The ServerName which is requested, is contained in the HTTP request headers, but before that the SSL encryption must be already setup. So the ServerName is only available after the encryption has been setup. Therefore Apache can never know which SSL certificate te serve up and wil just use the first one available on that particular IPaddress.
With the single dedicated IP we can configure domain-based wildcard SSL in centos + apache2.2 server.
Hope the configurations below will help you guys!!
NameVirtualHost IP:80
NameVirtualHost IP:443
Domain 1
<VirtualHost IP:80>
ServerName abc.domain1.com
DocumentRoot /var/www/html/domain1
</VirtualHost>
<VirtualHost IP:443>
ServerName *.domain1.com
DocumentRoot /var/www/html/domain1
SSLEngine On
SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /var/www/html/domain1/cert/5465456.crt
SSLCertificateKeyFile /var/www/html/domain1/cert/domain1.com.key
SSLCertificateChainFile /var/www/html/domain1/cert/g2-g1.crt
</VirtualHost>
Domain 2
<VirtualHost IP:80>
ServerName abc.domain2.com
DocumentRoot /var/www/html/domain2
</VirtualHost>
<VirtualHost IP:443>
ServerName abc.domain2.com
DocumentRoot /var/www/html/domain2
SSLEngine On
SSLCipherSuite ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /var/www/html/domain2/cert/5465456.crt
SSLCertificateKeyFile /var/www/html/domain2/cert/domain1.com.key
SSLCertificateChainFile /var/www/html/domain2/cert/g2-g1.crt
</VirtualHost>