CentOS 6.5 + Apache Virtual Host - apache

I have installed CentOS 6.5 on my VPS (IP 149.210.167.9). Eventually I want to serve multiple domains, but for now I only want to handle 1 domain in particular: aforismo.eu. When you surf to the IP directly it shows me an Apache test page, so that works. When I ping aforismo.eu it shows me the correct IP, so I think the DNS is setup correctly. If I'm missing something trivial, please teach me :)
What I did so far to handle this domain:
I) I've created /etc/httpd/conf.d/site-aforismo.conf
<VirtualHost *:80>
ServerAdmin webmaster#aforismo.eu
DocumentRoot /var/www/aforismo.eu/public/
ServerName aforismo.eu
ServerAlias *.aforismo.eu
ErrorLog logs/aforismo.error_log
CustomLog logs/aforismo.access_log common
</VirtualHost>
II) Modified a few bits in /etc/http/conf/httpd.conf:
Include conf.d/*.conf
NameVirtualHost *:80
III) Afterwards I've restarted apache
service httpd restart
IV) Checking httpd -S results in:
wildcard NameVirtualHosts and _default_ servers:
_default_:443 vps.vanoosten.me (/etc/httpd/conf.d/ssl.conf:74)
*:80 is a NameVirtualHost
default server aforismo.eu (/etc/httpd/conf.d/site-aforismo.conf:1)
port 80 namevhost aforismo.eu (/etc/httpd/conf.d/site-aforismo.conf:1)
wild alias *.aforismo.eu Syntax OK
But ... surfing to http://www.aforismo.eu (or http://aforismo.eu) does not work. Since it's not my everyday business, I'd sure miss something quite trivial, but I can't find out what it is. Can you help me a bit further? Much appreciated.

You may need to add Listen *:80.
You may also need to add UseCanonicalName off under <VirtualHost *:80>.
Edit:
Unless it's meant to be internal only, there is something wrong with your DNS. I can hit the IP but aforismo.eu doesn't resolve to anything.

Update: As you guys suggested, it turns out to be a DNS issue. I thought I had created an A record to the given IP. But ... in the interface of my DNS provider I had to use the #-character for the domain itself instead of to really write it down. So what I really created was an A-record for aforismo.eu.aforismo.eu. Fixed (and next time I promise to read the manual :P)

Related

404 Not Found The requested URL /xxxxx was not found on this server

Please i need help, I have gone through a couple of similar issues and how they were resolved and it seems mine is such a pain it just wont work.
I used a Turnkey Linux Appliance [OrangeHRM] and i want to use its Apache server to host another site/software [Sentrifugo] and it is so difficult, each time i host it only the default site shows up.
i have read through several similar issues here on stack overflow and it didn't work, i need someone to please take a look at my case.
Sincere appreciations in anticipation
Below is the output of grep "<VirtualHost" /etc/apache2/sites-enabled/*
/etc/apache2/sites-enabled/adminer.conf:<VirtualHost *:12322>
/etc/apache2/sites-enabled/orangehrm.conf:<VirtualHost *:80>
/etc/apache2/sites-enabled/orangehrm.conf:<VirtualHost *:443>
/etc/apache2/sites-enabled/sentrifugo2.conf:<VirtualHost *>
Good morning, based on what we discussed:
you have 4 VH (VirtualHost): *:12322, *:443, *:80, *
*:12322 is not a default port, it would have to be specified explicitly (http://SOMETHING:12322/...)
*:443: default SSL port (https://SOMETHING/...)
*:80: default http port (http://SOMETHING/...)
*: matches all ports
Now you are using http://IP/sentrifugo2/...
Using the IP address, Apache will check the VH in order and use the first one that matches.
If you ask for http://IP/..., since this is port 80 (default for http), Apache will match the third VH (the *:80 one).
But here you want the 4th one, the one with *
Solutions:
Works, but is not the best: define your 4th VirtualHost with a port. <VirtualHost *:80>. Then modify the order in which your VH appear in Apache and put the sentrifugo VH before the orangehrm.conf one. But that could create a new problem where the orangehrm.conf is not usable anymore... Keep reading...
Best: use name virtual hosting:
<VirtualHost *:80>
ServerName orangehrm.conf
...OTHER CONFIGURATION DIRECTIVES...
</VirtualHost>
<VirtualHost *:80>
ServerName sentrifugo
...OTHER CONFIGURATION DIRECTIVES...
</VirtualHost>
So you see, this way, Apache can diffentiate between the two *:80, using the requested domain (or name). On your client system, in /etc/hosts, define the two names:
10.0.0.18 orangehrm.conf
10.0.0.18 snetrifugo
So when you type http://orangehrm.conf or http://sentrifugo Apache will know which one you want.
Note: on Apache 2.4, this works no problem. On Apache 2.2, you need to specify NameVirtualHost directive (see Apache documentation on this).
Again works but not the best: might not be possible for you. You can split between the VH using a different IP address. Ex. 10.0.0.18 is orangehrm.conf and <VirtualHost 10.0.0.18:80> is used. Then 10.0.0.19 is sentrifugo, so <VirtualHost 10.0.0.19:80> is used (with Listen 10.0.0.19:80). But you must be allowed to configure extra IP addresses on your host for this...
another possibility: split on the port. <VirtualHost *:80> is for orangehrm.com, <VirtualHost *:81> is for sentrifugo. For this, you need to specify http://10.0.0.18:81/sentrifugo. This also requires Listen *:80 and Listen *:81.
In conclusion Apache needs a way to know which one you want. It can decide with: IP, Port, Name. Name is the most flexible.
IMHO using IP address is not the way to go. It works in simple setups, but quickly limits you. Use domain names. Here I showed you how to do it in your local host file, the "best-best" way to do is to set them up in DNS.

NameVirtualHost directive equivalent in Apache 2.4.6?

Overview of new features in Apache HTTP Server 2.4 states:
NameVirtualHost directive:
No longer needed and is now deprecated.
Can someone please explain the virtual host equivalent syntax to produce this behaviour in the new version of Apache?
<VirtualHost 127.0.0.3:80>
DocumentRoot /var/www/html3
ServerName site3.com
</VirtualHost>
<VirtualHost 127.0.0.3:80>
DocumentRoot /var/www/html4
ServerName site4.com
</VirtualHost>
My apologies everyone but I have since destroyed this server and so cannot supply the config file :(
Just FYI I have since seen an example online which placed the server name in the VirtualHost header as seen below which may have been the problem, though I have no way of knowing this until I get an opportunity to test it at some point in the future/
<VirtualHost site3.com:80>
DocumentRoot /var/www/html3
</VirtualHost>
Your configuration is correct and automatically behaves as if "NameVirtualHost 127.0.0.3:80" was present. If http://site4.com appears to be the default virtualhost:
make sure you're actually testing with "http://site4.com"
confirm it's not browser cache
try a command-line client
make sure the content really differs on disk
I agree with #covener. Apache enables SNI based on how many valid vhost blocks it detects for an IP address/port combo. Your question is best answered on apache's official Documentation:
https://httpd.apache.org/docs/2.4/vhosts/details.html
However, for full NameVirtualHost behavior, either pick an internal IP that is routing traffic to your server (use the same IP in all vhost config blocks), or use the wildcard (*):
<VirtualHost *:80>
<VirtualHost *:443>
I, personally, use the wildcard syntax and have roughly 10 different vhost configurations on my own server.
EDIT:
I just realized this post is 4 years old.

Apache different sites on different ports, still links to same site. Bind9 for domain names

I've been trying to create 3 different domains linking to 3 different sites on the same machine, 2 which works but the third on the different port links to the first page.
My apache config looks like this:
Listen 81
NameVirtualHost *:81
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/www
</VirtualHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /var/www/www2
</VirtualHost>
<VirtualHost *:81>
ServerName controlpanel.example.com
DocumentRoot /var/www/controlpanel
</VirtualHost>
I've used Bind9 to set up the domains.
www IN A 123.123.123.123
www2 IN A 123.123.123.123
controlpanel IN A 123.123.123.123
www and www2 works fine and shows the correct site, however controlpanel.example.com also links to the first www site. When I enter the port manualy on the ip, xxx.xxx.xxx.xxx:81, i get linked correctly. The thing is that I don't really know where I'm doing it wrong, this is the first time I'm trying anything like this. You got any ideas?
Im also running this on an old ubuntu 12.04 server.
Regarding where you're going in the comments for the previous answer:
You could add a port 80 virtualhost for controlpanel.example.com and put a single statement inside,
Redirect / http://controlpanel.example.com:81
The purpose of the ServerName is not to inform the browser what port your webserver is using. It's used for name-based virtualhosts and as a last resort for self-referential links (out of the box, self-referential links are generated with whatever the client already thought it was accessing via the Host: header)
But there is definitely something quite bizarre about your requirement. Usually the motivation is to not use custom ports, and if they are, to address the server with a low port and have the por remapped by some intermediary (load balancer, proxy).
If you want your third virtualhost to be simulataneously the defautl on port 81 and a name-based option on port 80:
Change
<VirtualHost *:81>
to
<VirtualHost *:80 *:81>
Apache finds the set of virtual hosts with the best IP:PORT based match first, then if NameVirtualHost also matches, starts looking at the ServerNames from that set.

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.

IP based VirtualHost and Apache

I have this webserver that have an IP address xxx.xxx.xx.x, I also have a website I want to publish, but I do not have any domain for my website yet.
So in my httpd-vhosts.conf file I have this setting:
<VirtualHost xxx.xxx.xx.x>
ServerName xxx.xxx.xx.x
DocumentRoot "C:\Sites\mysite"
</VirtualHost>
And since I dont have a domain I really want to use the IP address to reach my site, but I have tried this and it does not work. I guess you HAVE to set a server name in ServerName as the title says.
Are there any ways for me to make my website public through my IP address, if yes how can I do this?
Try
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\Sites\mysite
ServerName xx.xx.xx.xx
</VirtualHost>
Remember to restart apache,
You may also need to add,
Listen xx.xx.xx.xx:80
If you only have the one website on this server, you don't need a virtual host. Just set the DocumentRoot correctly and away you go. Also make sure Apache is listening on all IP addresses (Listen 0.0.0.0:80.)
If that doesn't work for you, from your command prompt do:
telnet xx.xx.xx.xx 80
GET /
and see what you get back - you should get your website's default page.
This is not a programming question.
But anyway,
Set the VirtualHost to * rather than a specific IP address. I don't think you need the servername either then.