Ec2 host multiple pages, server ignore virtualhost - apache

im new to amazon web services.
I have installed an ec2 instance with lamp, everything seems to be OK.
I manage the server through ssh,
I've created the
/etc/apache2/sites-available/jak-udelat-cz.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin info#jak-udelat.cz
ServerName www.jak-udelat.cz
ServerAlias jak-udelat.cz
DocumentRoot /var/www/html/jak-udelat.cz
LogLevel warn
ErrorLog /var/log/apache2/jak-udelat.log
CustomLog /var/log/apache2/jak-udelat2.log combined
Then I restarted the apache..
But when I run
sudo a2ensite jak-udelat.cz
, i get
ERROR: Site jak-udelat.cz does not exist!
The domain www.jak-udelat.cz is going on the server right, php works, mysql works, everything seems to be ok, instead of this...
Could you please point me out where I'm making mistake?

Your conf file is named jak-udelat-cz.conf, so you should do:
sudo a2ensite jak-udelat-cz

OK :D so, I changed almost everything like without seeing any change, so I absolutely out of mind tried reboot, then once more restart apache and it finally helped! :)

Related

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

virtualhost keeps redirecting to deleted alias information

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.

Query Regarding Apache Setup

I have 2 websites on a Ubuntu 14.04 Server with Apache. The websites lie in /var/www. I have bought a couple of domains from Godaddy. I have linked the domain and the machine's IP.
Lets say I have abc.com and xyz.com. When a user tries to access abc.com, I need to show him the website under /var/www/abc/index.html and similarly for xyz.com.
I researched and found that under /etc/apache2/ there is some settings file I need to change in order to do it but I am not sure what to do. Could anybody give me a hint on how I can achieve this?
A detailed answer can be lot helpful for understanding.
So after a lot of research, I have found the answer to my question. I will share the steps I did to solve it.
cd /etc/apache2/sites-available
sudo cp 0* abc.com.conf
sudo nano abc.com.conf
sudo a2ensite abc.com.conf
sudo service apache2 restart
The contents of abc.com.conf should be something similar to below code and don't touch anything else.
<VirtualHost *:80>
ServerAdmin admin#abc.com
ServerName abc.com
ServerAlias www.abc.com
DocumentRoot /var/www/abc/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Similarly do so for the next website also.

Error starting apache from terminal after removing MAMP

I removed MAMP recently.
When I try to start apache from Terminal using:
sudo apachectl -k restart
I am getting the message
Warning: DocumentRoot [usr/docs/dummy-host.example.com] does not exist.
First, make sure you're actually trying to execute the proper version of apachectl by issuing the following command:
which apachectl
(You don't want to see any MAMP references there).
Next, find your virtual hosts config (which is likely here if your MAMP references are gone)
/etc/apache2/extra/httpd-vhosts.conf
Make sure your virtual host definitions are good. (Sounds like you're referencing a bad one).
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Users/yourusername/Sites/mysite"
ServerName mysite.local
ErrorLog "/private/var/log/apache2/mysite-error_log"
CustomLog "/private/var/log/apache2/mysite-access_log" common
</VirtualHost>
(If you're using a custom server name other than 'localhost' like I've defined above, just be sure your /etc/hosts file is up to date with that entry like this:
127.0.0.1 mysite.local
Don't forget to restart apache!
sudo apachectl restart
You probably need to go to apache config file (something like etc/apache2/apache2.conf) and set it an existing document root directory. That is usually done with DocumentRoot directive in this file, or one of the included virtual host config definitions.
Make sure you comment out all the lines inside the /etc/apache2/extra/httpd-vhosts.conf file otherwise you will get the errors.

How to I point multiple URLs to the right directory?

I have a VPS running CentOS 5. I want to point multiple domains at the same VPS (point them at the same IP), but serve up distinct websites for each domain.
So, the setup I want is like this:
site1.com ----> 127.0.0.1 ----> /var/www/html/site1.com/
site2.com ----> 127.0.0.1 ----> /var/www/html/site2.com/
I've tried setting up virtual hosts through the CentOS GUI for Apache, but they don't seem to be working. Only the first virtual host added will work (i.e. If I add site1.com first, both domains direct to that site. If I add site2.com first, both domains direct to that site.)
What might I be doing wrong? Is there an effective step-by-step tutorial for newcomers to get me started?
Update
Please remember, I have little to no experience working with CentOS and Linux ... but I'm learning.
To those who asked to see the directives I'm using, here's what CentOS added to the bottom of /etc/httpd/conf/httpd.conf when I used the built-in Apache GUI:
<VirtualHost skylarkapp.com:80>
DocumentRoot /var/www/html/skylarkapp.com
<Directory "/var/www/html/skylarkapp.com">
allow from all
Options +Indexes
</Directory>
ServerName skylarkapp.com
</VirtualHost>
<VirtualHost eamann.com:80>
DocumentRoot /var/www/html/eamann
<Directory "/var/www/html/eamann">
allow from all
Options +Indexes
</Directory>
ServerName eamann.com
</VirtualHost>
At the moment, all traffic to both skylarkapp.com and eamann.com on this system direct to the content of /var/www/html/skylarkapp.com.
Also, I'm using my Windows hosts file to manually point eamann.com to this server (204.92.23.6) because I'm in the process of migrating a live site. I want to get things working on the server before I actually move things from one box to another.
Name-based virtual hosts must be turned on explicitly with NameVirtualHost *:80. See http://httpd.apache.org/docs/2.2/vhosts/name-based.html
This line:
<VirtualHost eamann.com:80>
won't work since eamann.com won't resolve to your CentOS server's IP address (only your Windows machine resolves eamann.com to 204.92.23.6). Try making apache listed on any IP by replacing with:
<VirtualHost *:80>
You probably also want:
ServerAlias www.eamann.com
to allow visitors to www.eamann.com to see the site as well. Restart apache after making these changes:
service httpd restart