Domains crossed over on digital ocean - apache

I have two domains. exampleone.com and exampletwo.com.
I followed this guide for adding multiple domains on the same server:
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-16-04
They are both on the same server. Somehow, blog.exampleone.com was created (out of nowhere). and it points to exampletwo.com.
If I click on the site in google, it shows blog.exampleone.com as the domain, but shows the content for exampletwo.com
How is this happening?
I've looked into the vhost files and everything seems correct.
Here is a sample vhost file:
<VirtualHost *:80>
ServerAdmin dave#example.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This should result in 2 separate sites on the same server. Instead, a blog subdomain was created on one site that points to the content on another site.
What should I do?
Thanks!

You neeed to specify the "ServerName" in your vhost file, something like :
<VirtualHost *:80>
ServerAdmin dave#example.com
ServerName blog.exampleone.com
DocumentRoot /var/www/html/exampleone.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.lognano
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
in fact, for each vhost file, you need to specify the ServerName to work properly with your subdomains!

Related

Apache2 redirecting to main site

I'm trying to host multiple websites off a digitalocean droplet using apache2's virtualhosts.
I have a config file for the main one, (pcnerd19.com) and one for the other, (efferri.ga). Whenever I type efferri.ga in firefox though, it just redirects back to pcnerd19.com I've restarted apache2, and made sure both sites are enabled. The is an index file at the root of efferri.ga as well. Here are my config files.
pcnerd19.com:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName pcnerd19.com
ServerAlias www.pcnerd19.com
ServerAdmin ruby#pcnerd19.com
DocumentRoot /var/www/wordpress1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/pcnerd19.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/pcnerd19.com/privkey.pem
</VirtualHost>
<Directory /var/www/wordpress1>
AllowOverride All
</Directory>
<IfModule>
efferri.ga:
<VirtualHost *:83>
ServerName efferri.ga
ServerAlias www.efferri.ga
ServerAdmin ruby#pcnerd19.com
DocumentRoot /var/www/efferri
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
It is worth mentioning I used certbot to get an ssl certificate on pcnerd19.com, and my droplet is running Debian.
From this page where someone had a similar problem, this answer might help:
When looking at your VirtualHost configuration, you’re setting a ServerAlias that defines the www. access point for each domain, but you’re missing a DNS entry on both domains that points www. to your domain. Since the DNS record isn’t set, Apache will handle it the best way it knows how, which may or may not be correct.
So what I would recommend doing is adding an A entry to each domains’ DNS records. The A entry should point to the same IP that your domain points to (i.e. the public IP of the Droplet).
So www should be an A entry that points to 46.101.19.243 in your case. Since it looks like your using DigitalOcean for your DNS, you can make these changes through their control panel and the updates should take effect pretty quickly. If they don’t, you may need to clear your browsers cache and then try to access your domains again.

Virtualhost configuration not manage correctly requests

I have the following Virtualhost config in httlp-vhosts.conf:
<VirtualHost *:80>
ServerName rest.budgettracker.loc
DocumentRoot "C:/xampp/htdocs/budget-develop/budget-develop/api/public"
ErrorLog "logs/rest.budgettracker.loc-error.log"
CustomLog "logs/rest.budgettracker.loc-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName dev.budgettracker.loc
DocumentRoot "C:/xampp/htdocs/budget-develop/budget-develop"
ErrorLog "logs/budgettracker.loc-error.log"
CustomLog "logs/budgettracker.loc-access.log" common
</VirtualHost>
When I enter dev.budgettrackerpro.com in the browser it goes to the rest.budgettrackerpro.loc virtualhost container.
If I remove the Virtualhost container for the rest request it directs correctly to the correct html/javascript code. Obviously I need the rest call to make it work correctly. I have researched this until I am blue in the face, what am I doing wrong? Please help
You are asking for dev.budgettrackerpro.com. Your configuration is for dev.budgettrackerpro.loc.
What happens is:
Apache sees that your request is on port 80 (http://...)
It checks which VirtualHost are configured to take traffic from port 80.
Here it finds 2. 1) rest.budgettracker.loc 2) dev.budgettracker.loc
Since the domain you asked (the .com) does not match either 1) or 2), Apache assumes that the VirtualHost it should use is the first one it found.
Apache when finding multiple VirtualHost or finding none that match uses the first one in the file (top to bottom).
To solve this:
Request http://dev.budgettracker.loc
Modify your VirtualHost to accept traffic form .com as well, like so:
<VirtualHost *:80>
ServerName dev.budgettracker.loc
ServerAlias dev.budgettracker.com
DocumentRoot "C:/xampp/htdocs/budget-develop/budget-develop"
ErrorLog "logs/budgettracker.loc-error.log"
CustomLog "logs/budgettracker.loc-access.log" common
</VirtualHost>
Notice the new line, ServerAlias dev.budgettracker.com. You can have multiple ServerAlias in a VirtualHost, but only one ServerName.

How to setup two virtual hosts in CentOS?

I have two domains I'm trying to host on the same IP. This is what I've been trying, but it doesn't work:
<VirtualHost host1.me:80>
ServerAdmin admin#menet.me
DocumentRoot /var/www/html/host1/
ServerName host1.me
ErrorLog logs/host1-error_log
CustomLog logs/host1-access_log common
</VirtualHost>
<VirtualHost host2.me:80>
ServerAdmin admin#menet.me
DocumentRoot /var/www/html/host2/
ServerName www.host2.me
ServerAlias host2.me
ErrorLog logs/host2-error_log
CustomLog logs/host2-access_log common
</VirtualHost>
What should I put in my httpd.conf?
if you are accessing the urls locally i.e. on server itself,
then u need to add their entries in /etc/hosts file.
eg: suppose ur server ip is 192.168.1.1, thn put following entry in hosts file:
192.168.1.1 host1.me host2.me www.host2.me
save the file...
and then check...
hope this helps :)

drupal and wordpress together on one server

I have two domains:
example1.com - is a drupal site.
example2.com - is a wordpress multisite.
Both domains live on the same physical host. I am using Ubuntu 14.04 and Virtualhosts.
Everytime I enable example1.com when I navigate to example2.com (or any domain in my multisite) I get the drupal install page. I should be seeing example 2's index page. Can anyone help? Here are the vhost.conf files
example1 vhost.conf
<VirtualHost *:80>
ServerName example1.com
ServerAlias *.example1.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
example2.conf
<VirtualHost *:80>
ServerName example2.com
ServerAlias *.example2.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/example2.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
When I disable example1.conf everything with the wordpress multisite (example2.conf) works as expected...
When I try to specify a domain name on the virtualhost (like
I get an 500 error.
Can anybody point me in the right direction?
It looks like there was a two part problem here. I hadn't properly closed a tag
in my .htaccess file for site example2.
When I removed this, I would get the drupal install page for example1 and example2. What I wound up doing to resolve this issue was to move both virtualhosts into one .conf file in Ubuntu.... for whatever reason that seemed to resolve the issue.

Apache Virtual Domains for staging

We're trying to set up a staging service for domains configured on a server.
At present we have the following in our DNS and it is pointing to our server correctly.
*.server001.stage.ourdomain.com.au
This serves the default site located at:
/Server/http/_default
What I would like it to do is load a site based by the information in place of the wildcard.
Example;
test.com.server001.stage.ourdomain.com.au
would return the contents of:
/Server/http/test.com
Remembering that we might be using .com.au domain names too, so there'd be a requirement for anything before the "server001" part.
You should define another <VirtualHost> block for test.com.server001.stage.ourdomain.com.au with its DocumentRoot pointing to /Server/http/test.com.
Something like this
<VirtualHost *:80>
ServerAdmin webmaster#test.com
DocumentRoot /Server/http/test.com
ServerName test.com.server001.stage.ourdomain.com.au
ErrorLog /var/logs/httpd/test.com/error_log
CustomLog /var/logs/httpd/test.com/access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#server001.stage.ourdomain.com.au
DocumentRoot /Server/http/_default
ServerName *.server001.stage.ourdomain.com.au
ErrorLog /var/logs/httpd/server001.stage.ourdomain.com.au/error_log
CustomLog /var/logs/httpd/server001.stage.ourdomain.com.au/access_log common
</VirtualHost>
The wildcard VirtualHost should be the last one since apache picks up the first VirtualHost that matches.
Have a look at the Dynamically Configured Mass Virtual Hosting chapter in the manual. It basically explains how to use the VirtualDocumentRoot directive.