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

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

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,

Xampp vhost cannot load the virtualhost without port number

I am not sure if this is a repost but I couldn't find a solution.
I have an application setup in my local environment which the name I added in my hosts file (C:\Windows\System32\drivers\etc) as follows,
127.0.0.1 skeletonpage.lk
Also I added a record in httpd-vhosts.conf as below.
<VirtualHost *>
DocumentRoot "C:/xampp/htdocs/skeleton/public"
ServerName skeletonpage.lk
<Directory "C:/xampp/htdocs/skeleton/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I run the application on browser I can only load the homepage with the port number tagged with the site name. Ex: http://skeletonpage.lk:83/
I have both XAMPP and WAMP in my machine and my site runs in XAMPP for which the port 83 is given, If I remove :83 it loads the homepage of wamp server which has port 80.
I tried removing and modifying above code snippet but still cant get rid of port 83. I know this is something simple, but would be glad if someone can help.
I modified as <VirtualHost *:83> also <VirtualHost 127.0.0.1:83> and restarted XAMPP also modified NameVirtualHost *:83 but no use.

Apache VirtualHost : multiple sites on same IP

Let assume that blah.com, blah2.com all point to the same server with IP=5.31.111.7.
I would like that:
accessing blah.com serves /var/www/site1
accessing blah2.com serves /var/www/site1
accessing 5.31.111.7 serves /var/www/site2
I tried
<VirtualHost *:80>
DocumentRoot /var/www/site1
</VirtualHost>
<VirtualHost 5.31.111.7:80>
DocumentRoot /var/www/site2
</VirtualHost>
but now everything goes to /var/www/site2, which is not what I wanted.
How to configure the VirtualHost, such that the served website depends on the URL ?
PS: why should I do this in /etc/apache2/sites-enabled/000-default instead of /etc/apache2/apache2.conf ? I don't understand this sites-enabled / sites-available/default naming... Why are there so many different config files by default on Debian, for such a simple thing?
What you want to do is called Name-Based Virtual Hosting, you'll need
NameVirtualHost *:80
to enable it on port 80, and for each VirtualHost, you need to give the name(s):
<VirtualHost *:80>
ServerName blah2.com
ServerAlias www.blah2.com
DocumentRoot /var/www/site1
</VirtualHost>
Note that there are limitations on SSL/TLS when doing name-based virtual hosting, but it's a bit of a moot point since post-POODLE, people start to require TLS anyway, so ancient browsers are out of luck anyway.
As to the config files, it's very very useful to have two classes of config files: the ones with defaults that a package update will overwrite, and your local ones that it will not touch, or better even, a directory full of the former and a directory full of the latter. (Because additional packages might want to make configuration settings, they'll all install in the former place, and you should only ever change/override config in the second place.)

XAMPP apache server not using the ports I desire, not certain why

So, I've been setting up this HTTP server for a school project that has to be able to maintain multiple domains through virtual hosts. Using XAMPP I have my server set up, I thought I'd done it properly but perhaps not.
I had heaps of issues with not being able to listen to a port, to solve this I used (in httpd.conf under apache/conf/)
Listen 0.0.0.0:8080
ServerName localhost:8080
If I used 80/81/8080/321/any combination that did not have the prefix 0.0.0.0 it told me the port could not be listened or whatever (sorry, a little rusty with my syntax).
I set up my first virtual host up like so (under apache/conf/extra/httpd-vhosts.conf):
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "H:/xampp2/xampp/htdocs"
ServerName localhost:8080
<Directory "H:/xampp2/xampp/htdocs">
Option Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I thought this seemed all good and well and I don't believe I've modified anything else. To me, I would expect that this means my Apache server would use port 8080 for the server? However, when I start Apache in XAMPP it states quite clearly
Apache started [Port 80]
Why would this be port 80?
In conjunction, localhost:8080 doesn't navigate me to the documents, but localhost:80 or localhost do. I presume that this just means it's still on port 80. I've tried resetting my computer and XAMPP.
If you need any more information, please let me know. I tried following guides such as this one: http://ailoo.net/2008/07/set-up-multiple-virtual-hosts-on-xampp-for-windows/
Cheers.
Oh, I also edited my Windows HOSTS file; it looks like so:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
127.0.0.1 localhost:8080
Edit: New error... Now getting this when I init, doesn't seem to be affecting it though:
ERROR: Status Check Failure [3]
This program must be run from your XAMPP root directory.
It is being run from teh root directory as far as I can tell.
Ok Im not advanced in this area either. However after much playing around with XAMPP and following a few different guides I got mine working.
The Host under drivers seems abit weird. I declared mine as:
127.0.0.1:8080 test.localhost.com
127.0.0.1:8080 test2.localhost.com
Back up you Xampp, then extract a clean install to C: - Just because that Status check failure sounds like bad news.
!Remember to run setup_xampp.bat from the xampp directory and install the apache service!
Then under you httpd.conf add:
ServerRoot C:\xampp\apache
Listen 7070
Listen 8080
Listen 9090
Apache might not like that at first but meh.
The ServerRoot may already be declared above the Listen spot so just double check.
After that head to C:\xampp\apache\conf\extra.
Edit the httpd-vhosts.conf.
Under the section Name-based virtual hosting add:
NameVirtualHost *:7070
NameVirtualHost *:8080
NameVirtualHost *:9090
There will be a couple of examples of virtual hosts below that. Add:
<VirtualHost *:7070>
DocumentRoot "C:/xampp/www/YOURWEBSITEDIR1"
ServerName test.localhost.com
<Directory "C://xampp/www/YOURWEBSITEDIR1">
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:9090>
DocumentRoot "C:/xampp/www/YOURWEBSITEDIR2"
ServerName test2.localhost.com
<Directory "C://xampp/www/YOURWEBSITEDIR2">
Allow from all
</Directory>
</VirtualHost>
Not the double slash in the Directory tag. Now ensure there is an index.html under each of those directories. Restart the apache (Stop, start).
I cant navigate to the test.localhost.com URLs, probably due to the fact they are terribly wrong in the HOSTs config. Though I can connect to 127.0.0.1:7070, 127.0.0.1:9090 and access the webpages from there.
Also 127.0.0.1:8080 connects me to the xampp welcome panel that localhost used to connect you too.
Hope this helps and good luck!
I'm pretty sure that saying 'listening on port 80' is hard-coded into XAMPP, regardless of the port you use. Thus, your code should work fine.
In my .conf file, it just says "listen 80" instead of Listen 0.0.0.0:8080
Cheers.

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