How to I point multiple URLs to the right directory? - apache

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

Related

WAMP 3.1 setup on Windows 10. Can't access online

I've been trying two days straight to make this work. I want to make my server available online so I can work with another guy on this project. The goal is mainly to have two things:
The www website available through my public ip
MySQL available to him so he can work
This computer has:
Windows 10 Pro
WAMP 3.1
Node.JS
I went through the configuration of the vhost of wamp, port forwarding in my router and this doesn't work:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName 192.168.2.51
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I put back what was in http.conf because that's the first thing I modified at first until I discover the new WAMP wasn't using this anymore.
I though Node.JS could conflict so I shut it down. I also shut most process using port 80 but still no luck.
I used an online port checker. The result is positive and it seems to go through, at least from their POV. And I did a netstat to check if I had 0.0.0.0:80 so everything seems fine on that side.
The port 80 tester of WAMP even says it's fine so I'm guessing it must be in the Virtual host but I have no idea how to set it up properly and documentation is not helping a lot.
What am I missing?
regards,

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

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.

XAMPP Apache site-root-relative links work locally, fail when accessing dev site via remote machine over LAN

Am trying to set up multiple site development areas on a single server machine, then work on content from other computers over LAN. (Excuse the general wording of my questions, the site keeps preventing me from entering example URLs, etc.)
When I work directly on the server machine, entering
my-virtual-host-name:port#
as the URL everything works beautifully. It correctly resolves all links, image references, etc, as being relative to the site root.
When I connect from a different machine, over our Lan, entering
server-ip-address:port#
I get automatically redirected to a default XAMPP welcome page (So I am at least connecting to the server)
I figured how to setup an Alias statement, so that, for example something like
server-computer-ip-address:port#/alias-for-file-path
gets me to the home page for my site. But subsequently when I click on links, for example
/products-services
which I would want to go to
server-ip-address/alias-for-file-path/products-services
it instead resolves to
server-ip-address/products-services
Relevant settings on the computer running the Apache server
IP Address: 192.168.22.12
In Windows Host file: 127.0.0.1 localhost mySiteName
In httpd-vhosts.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "D:\companysites\newproducts\mysite"
ServerName mySiteName
<Directory "D:\companysites\newproducts\mysite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
In httpd.conf (assigning alternate port to Apache, since 80 is otherwise used):
Listen 3399
Have tried a bunch of things not detailed here, trying to figure out how to correctly define some combination of server machine and remote machine virtual host definitions and url settings, as well as much web searching and zero luck so far!
At present you've set it up so all Virtual Hosts are listening for the same connection. Same ip from all ports. *
I figured it out, finally! Hopefully this will be useful and clear to someone else! (I am new to this, so may be obvious to others - there were some basic things I didn't understand and now do...)
In httpd-vhosts.conf file, you can:
Create any number of "Listen" statements, each with a unique port number. So, for example.
Listen 8885
Listen 8886
Listen 8887
Then you can create any number of VirtualHost definition sections, associating one of the above ports with each, for example:
NameVirtualHost *
<VirtualHost 192.168.22.11:3399>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 192.168.22.11:3388>
DocumentRoot "file-system/path"
ServerName mySiteName
<Directory "file-system/path">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When connecting to the server from a remote computer, it is not possible to use any combination of alias server names and/or alias file path names (at least, didn't work for me - if there is a way, I'd be interested to know). Instead, always enter ip-address:port#, for example, enter, as the URL to one of the defined sub-domains on the server machine:
192.168.22.11:3399

Only activate web sharing that I can use virtualhost with apache on Mac OS

I have configure httpd.conf and httpd-vhosts.conf, when I active the web sharing the virtualhost is useful, but when I close web sharing and start apache, the virtualhost doesn't work
Here is my virtualhost config
<VirtualHost *:80>
DocumentRoot "/Users/lch/Sites"
ServerName myhome.com
</VirtualHost>
<Directory "/User/lch/Sites">
Options None
Allow from all
</Directory>
And, here is error short-cut:
I am a newer for Mac OS, and I come from china.
Thank you for read my question.
Two things to check:
Is the include for httpd-vhosts.conf uncommented in httpd.conf? I believe it's commented out by default.
Have you added myhome.com to your hosts file? Make sure you've got the following entry in /etc/hosts: 127.0.0.1 myhome.com