Apache vhosts on localhost - apache

I managed to set up virtual hots on my local machine, but I kinda run into a wall now.
Normally, when you type localhost/ into browser you will see what you are supposed to see. But after I have set my virtual hosts, anything I type goes to the vhost. I cant figure a way to have a virtual host AND the old functionality together.
Here is my vhost file (btw, I am using xampplite)
<VirtualHost domain.eu>
ServerName domain.eu
DocumentRoot /www/domain
ServerAlias *.domain.eu
</VirtualHost>
<VirtualHost domain.sk>
ServerName domain.sk
DocumentRoot /www/domain
</VirtualHost>
The second one gets redirected to sk.domain.eu via htaccess. When I add these 3 lines to vhosts, localhost starts working, but even the other vhosts go to /www/
<VirtualHost localhost>
DocumentRoot /www
</VirtualHost>
But to comment/uncomment these 3 lines everytime I need to localhost is stupid. Any advice how can I keep both of them working together?
Thanks for your time

You really shouldn't be using domain names in the VirtualHost declarations.
If these three virtual hosts have different IP address, you should be putting their respective IP addresses into the VirtualHost blocks, and never mention NameVirtualHost.
If they use the same IP address, you must be using NameVirtualHost, and then you must, in each virtual host, repeat the name in the very same spelling that you did in the NameVirtualHost declaration.

Try adding this before the VirtualHost containers:
NameVirtualHost localhost
NameVirtualHost domain.sk
NameVirtualHost domain.eu

Related

How to host 2 projects on 2 different subdomains using virtual hosts in MAMP

I'm not quite sure what I'm trying to do is even possible.
Currently I'm using MAMP to host my projects myself. These projects are hosted and can be accessed by people who know my IP address when they type my IP address in their URL bar. When they access my IP, my they see a list of my project directories like this:
I am wondering if it is possible to make it so that when someone types charter.54.135.14.176 he sees the content of the charter folder and when he types LeagueOfLegendsFrontend.54.135.14.176 he is presented the content of League Of Legends Frontend folder.
I've been looking at tutorial videos about virtual hosts and I was left confused. I understand I have to do 2 things:
First, go to httpd-vhosts.conf and create a virtual host for each project. Something like this:
<VirtualHost *:80>
ServerName ???
ServerAlias ???
DocumentRoot "C:\MAMP\htdocs\Charter"
</VirtualHost>
<VirtualHost *:80>
ServerName ???
ServerAlias ???
DocumentRoot "C:\MAMP\htdocs\League Of Legends Frontend"
</VirtualHost>
I'm kind of clueless what am I meant to write on ServerName and ServerAlias
And secondly, I need to go to the hosts file and add this:
54.135.14.176 ???
And lastly I need to include virtual hosts by uncommenting Include conf/extra/httpd-vhosts.conf in httpd.conf file. Sadly I'm stuck on the rest.
You need to allocate two different IP addresses for your projects. So, the desired configuration may look like this:
<VirtualHost 127.0.0.2:80>
ServerName charter.zxc
DocumentRoot "C:\MAMP\htdocs\Charter"
</VirtualHost>
<VirtualHost 127.0.0.3:80>
ServerName lol-frontend.zxc
DocumentRoot "C:\MAMP\htdocs\League Of Legends Frontend"
</VirtualHost>
You, of course can add directory settings, logs and other things if necessary, but I only show the very basic setup. Then in your hosts file add:
127.0.0.2 charter.zxc
127.0.0.3 lol-frontend.zxc

Multiple web applications with Apache 2.4

I want to have two webapps (webapp1 and webapp2 resident under /var/www/html/webapps/), both using PHP and JSP, running on the same machine:
Apache 2.4
Tomcat 7.0.50 (+APJ connector)
and want to make them accessible through the following URLs (with identical IP and ports):
localhost/webapp1
localhost/webapp2
I am aware of Virtual Hosts facility. The problem is that Apache seems to "see" only the first site available: whenever I look for localhost/webapp2, I get a 'Not Found' error. Note that if I look for "localhost:8080/webapp2" (i.e., bypassing apache2) everything works fine.
Each webapp has its own conf file under sites-available directory. For example, in webapp2.conf I have
JkMountCopy On
JkMount /webapp2/* tomcat_worker
How can I solve?
From the documentation
Note
Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site. You can put entries in your hosts file for local testing, but that will work only from the machine with those hosts entries.
Listen 80
Listen 8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot "/www/domain-80"
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot "/www/domain-8080"
</VirtualHost>
<VirtualHost 172.20.30.40:80>
ServerName www.example.org
DocumentRoot "/www/otherdomain-80"
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.org
DocumentRoot "/www/otherdomain-8080"
</VirtualHost>
If you want additional help, show us your configuration files related.

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.

Apache multiple domains setup

I've got a pretty straightforward issue with a linux based Apache 2.2 server I am setting up. I want to setup two totally different domains on the same server.
But it only serves content from the first tag! I've searched StackOverflow and read items at Apache.org but no luck.
I followed the directions on Apache.org and put these two sections at the bottom of my http.conf file.
<VirtualHost *:80>
DocumentRoot /var/www/mydomain1
ServerName sub1.mydomain1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/mydomain2
ServerName sub2.mydomain2.com
</VirtualHost>
Now when I use a browser to go to: http://sub1.mydomain1.com it comes up fine. But if I go to http://sub2.mydomain2.com I still only get the content that located in /var/www/webfiles/mydomain1.
I did many of the obvious things such as:
- service httpd restart
- I changed the order of the two entries in my httpd.conf and once again, it only serves the first one in the list.
- One support doc I had Googled said to make sure to have the following entry point to a valid domain on your system. So I entered this (but it didn't change anything):
ServerName sub2.mydomain2.com:80
It must be something silly but I can't figure it out!
Ok, I figured it out. It was pretty silly. I just needed to uncomment this line so I would actually use all the virtual hosts:
NameVirtualHost *:80
You need to set up the two domains in two separate virtual hosts. Generally when I do this I like to split off an include directory full of virtual host files, with each file containing one virtual host.
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "/var/www/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "/var/www/site2"
</VirtualHost>

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.