virtualhost keeps redirecting to deleted alias information - apache

I have a DigitalOcean droplet (i.e. a VPS server), with Ubuntu 14.04 and Apache 2.2.
I had 4 virtualhosts configured, with 4 different domains pointing to 4 different folders, no problem.
I needed to point a 5th domain (let's call it www.someshop.tld) containing a PrestaShop installation.
I added the following Alias to the apache2/sites-available/domain1.conf file so that www.domain1.tld/someshop would lead to www/prestashop, and it worked fine
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
Alias /someshop /www/prestashop #Alias line
</VirtualHost>
I did this as a temporary measure so I could have a working site publicly accessible, (so I could access www/prestashop publicly before I had configured www.someshop.tld DNS settings, 'A' record, Nameservers, etc.).
I now don't need to do this any more, so I deleted the Alias line from the .conf file so it looks like this:
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /www/directory1
</VirtualHost>
and added a new someshop.conf that looks like this:
<VirtualHost *:80>
ServerName www.someshop.tld
DocumentRoot /www/prestashop
</VirtualHost>
I then re-enabled both the .conf files in apache2/sites-enabled, and restarted apache with service apache2 restart.
However, when I go to www.someshop.tld, it continues to do a URL redirect to www.domain1.tld/prestashop (where there's this message: "Not Found, The requested URL /someshop was not found on this server").
I waited for a couple of hours before posting this question because I thought it might just be a "propagation" issue. So far it's still doing this.
My question: is this something that should clear up by waiting for it, or do I need to fix something else? E.g., is there some way for me to flush the old virtualhost Alias information?

Have you tried removing the site from apache config?
$ sudo a2dissite test.com.conf #Remove symlink
$ sudo service apache2 reload
This would remove the symlink. You can then create the symlink again with the proper configurations that you like.

Related

Request to apache2 server always redirects to /var/www (Index of /) site

I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html. I have not registered an official domain but setup /etc/hosts/ to resolve example.com to the IP address of my server.
I created another conf file called example.conf under /etc/apache2/sites-available and enabled it with sudo a2ensite example.conf and disabled the 000-default.conf.
Now whenever I go to example.com in my browser I get served:
.
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html I get served the correct index.html.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/ as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.

Apache vhost config on non-standard port - only the first vhost is ever served

I am trying to serve 2 sites via Apache (v2.4.7 on ubuntu 14.04 LTS) on a non-standard port (8787). This is to accommodate a proxy setup (I have nginx serving other sites on port 80 on the same dedicated server). I am pretty confident the proxy configuration is fine but the vhosts seem to not be getting respected at the level of Apache (i.e. when I hit port 8787 directly, which nginx is not touching). The set up I have is seemingly very straightforward and as follows:
<VirtualHost *:8787>
ServerName site1.com
ServerAlias www.site1.com;
DocumentRoot "/var/www/site1.com"
<Directory "/var/www/site1.com">
AllowOverride All
</Directory>
</VirtualHost>
And...
<VirtualHost *:8787>
ServerName site2.com;
ServerAlias www.site2.com;
DocumentRoot "/var/www/site2.com"
<Directory "/var/www/site2.com">
AllowOverride All
</Directory>
</VirtualHost>
I also have a "Listen 8787" line replacing the "Listen 80" line in my top level /etc/apache2/ports.conf file. This is the sum total of the custom configuration I have done. Both sites have been enabled with a2ensite and the 000-default vhost has been disabled. I double checked that this worked by looking at the symlinks in /etc/apache2/sites-enabled. I've restarted Apache several times (w/ sudo) and rebooted the whole machine several times. No matter what, when I hit http://site2.com:8787 (and also http://site1.com:8787) I am served site1.
I have looked around everywhere to try and surface the specific thing that might be causing this and I am completely out of ideas. If anybody has dealt with this please let me know and I will follow up with a status on the fix right away.
Updating this: I resolved the problem. It was actually the trailing semicolons on certain lines of the vhost conf which I'd accidentally inserted (I guess I'd been editing too many Nginx conf files). I think perhaps they were being treated as part of the hostname by Apache

Running multiple domains on same server

I have a Ubuntu server running Apache and have 3 sites under /var/www/website/abc, /var/www/website/xyz and /var/www/website/lmn. I have 3 domains (www.abc.com, www.xyz.com, www.lmn.com) mapped to same machine (mapped same ip to 3 different domains on godaddy).
So I googled around and found this link - virtual host setup and made abc.com.conf in /etc/apache2/sites-available/ and correspondingly for other sites. Enabled the sites and then restarted apache but same site(/var/www/website/abc) appears on all 3 domains. I rechecked the paths but they seem to be correct. I can't figure out what is wrong. How can I route them to their corresponding sites?
It would be helpful in the future if you share your code (in this case the apache config files) to figure out what's wrong. In any case, this is roughly how the files can look (they don't have to look like this, there are other ways it can be configured).
First check /etc/apache2/apache2.conf and make sure you see the following code:
IncludeOptional sites-enabled/*.conf
The apache2.conf file is the primary configuration file. That line above includes all of the configuration files in the site-enabled folder. If you use a Red Hat derived OS you'll notice that the configuration file structure is different (Debian derivatives like Ubuntu like to split everything up into tons of configuration files, Red Hat derivatives keep it together)
Make sure that each of the files in the sites-enabled folder includes lines that look like this.
For abc.com.conf:
<VirtualHost *:80>
ServerName www.abc.com
DocumentRoot /var/www/website/abc
</VirtualHost>
If you also want "abc.com" to point to this virtual host enter "ServerAlias abc.com" underneath the ServerName line. What you're doing here is creating a VirtualHost block for any ip address (*) on port 80 (:80). You could replace the * in the opening VirtualHost line with your external ip address if you want to make sure that the VirtualHost is only matched to a particular ip (this is only potentially needed if there are multiple external ips pointing to your webserver). The ServerName line tells apache to match this VirtualHost whenever the Host HTTP header is www.abc.com. ServerAlias can be used to specify additional Hosts to match. Remember that www.abc.com and abc.com are treated as different Hosts. The DocumentRoot line sets the directory from which files are served.
Similarly for xyz.com.conf:
<VirtualHost *:80>
ServerName www.xyz.com
DocumentRoot /var/www/website/xyz
</VirtualHost>
If you also want "xyz.com" to point to this virtual host enter "ServerAlias xyz.com" underneath the ServerName line.
And finally for lmn.com.conf:
<VirtualHost *:80>
ServerName www.lmn.com
DocumentRoot /var/www/website/lmn
</VirtualHost>
If you also want "lmn.com" to point to this virtual host enter "ServerAlias lmn.com" underneath the ServerName line.

How to setup DEV/PROD website on public IP

This is for
Apache/2.4.7 (Ubuntu)
Ubuntu 14.04 LTS
I have a server with a certain IP address (example 22.22.22.22). I want to setup a DEV, a TEST and PROD environment.
for example if I go, from any computer in the world
1) to http://22.22.22.22 then I will hit the production website
2) to http://22.22.22.22/dev then I will hit the development website
3) to http://22.22.22.22/test then I will hit the testing website
How can I set this up?
Please share your suggestions and thoughts around this.
Thanks!
Not exactly what you asked for—I would take a slightly different approach. You will have a domain name, say example.com. You would have www.example.com and example.com point to your production site. Then you could have dev.example.com and test.example.com point to their respective sites. All of the DNS entries would still point to 22.22.22.22, but you would set up Apache to deal with them differently. This uses Apache named virtual hosts.
On the standard install of Apache, the site configurations should be in /etc/apache2/sites-available. To start with, there should be a configuration file named default. Create a new file prod with contents like the following:
# /etc/apache2/sites-available/prod
<VirtualHost 22.22.22.22:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/prod/html
(etc.)
</VirtualHost>
I've got the basics there, but you can look at the default for other directives you'll want there.
Next you create files for dev and test. Like so:
# /etc/apache2/sites-available/dev
<VirtualHost 22.22.22.22:80>
ServerName dev.example.com
DocumentRoot /var/www/dev/html
(etc.)
</VirtualHost>
It should be basically the same as prod, but different DocumentRoot and ServerName. The config for test will be almost the same too.
Once you have these set up, you just need to enable them. Run:
sudo a2ensite dev
...this enables dev. same thing again for test. After you run this, you should see the files are now also symlinked in /etc/apache2/sites-enabled. (The a2ensite command creates the symlink.)
Next, you just restart Apache. One way is: sudo service apache2 restart

Multiple domain names on a single server

Sorry my English
I have Ubuntu 12.04 openVZ VPS, with Apache and Passenger installed, to run Ruby site. That site have several faces which available (not yet) from different domains. In /etc/apache2/sites-available I created file site1.com which contains this:
<VirtualHost *:80>
ServerName site1.com
DocumentRoot /home/happy_buddha/Sites/rubysite/public
<Directory /home/happy_buddha/Sites/rubysite/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Previously I created A record on site1.com domain which contains server's ip.
Now if I going to site1.com browser's window contains this:
What I'm doing wrong?
you can not give virtual host name same as other's.
Like you said " I created A record on site1.com domain which contains server's ip." then you have to change your virtual host's name. Try with different name. for eg site2.com or site1.local
Make sure that you have NameVirutalHost *:80 set in your apache config - this will probably be in /etc/apache2/ports.conf on your Ubuntu server.
It sounds like the new site you created is acting as the default virtual host which is why you can't see the site you had before.
That said, if you actually visit site1.com, then I might expect to see the result you get, I don't know where the config is done for interpreting the ruby code but this might need to be part of the VirtualHost too.