Apache Virtual Host (Subdomain) access with different computer on LAN - apache

I am currently trying to configure the Virtual Host (Subdomain) of my Apache HTTP Server so it can be accessed with another computer on my LAN. The current setup of Apache with PHP and MySQL works locally on the same physical machine.
So I have two Virtual Host setup (development and cms) running on a non-default port of 50080. The machine of the server have a IP of 10.0.0.10. From the same physical machine, I can access the two Virtual Host using:
development.localhost:50080
cms.localhost:50080
From a different physical machine, I can access the root of the server using:
10.0.0.10:50080
But I cannot or do not know how to access the Virtual Host from the different machine. I tried something like:
development.10.0.0.10:50080
cms.10.0.0.10:50080
But they do not seem to work.
Here's how my httpd-vhosts file looks like:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
I read some of the other post here and the Apache forum, but there's not exact case for this.
I was wondering how I can access the Virtual Host (Subdomain) from another machine and keep the same port if possible.
Thanks in advance

Ok, I figured it out, here are the configuration if anyone else is looking for this:
==================================================================================
Machine A (Apache HTTP Server):
httpd-vhost:
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias alias <!-- Added -->
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.phoenix <!-- Added -->
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
hosts:
127.0.0.1 development.localhost
127.0.0.1 alias
127.0.0.1 development.alias
==================================================================================
Machine B (Guest Machine):
hosts:
10.0.0.10 alias
10.0.0.10 development.alias
From the second machine, you should be able to access with "alias" and "development.alias"

I suggest making the following change (add the ServerAlias lines):
NameVirtualHost *:50080
<VirtualHost *:50080>
DocumentRoot "C:/www/HTTP"
ServerName localhost
ServerAlias cms.myserver.com
</VirtualHost>
<VirtualHost *:50080>
ServerAdmin administrator#development.localhost
DocumentRoot "C:/www/HTTP/development"
ServerName development.localhost
ServerAlias development.myserver.com
ErrorLog "logs/development.localhost-error.log"
CustomLog "logs/development.localhost-access.log" common
</VirtualHost>
Restart Apache to ensure the changes take effect.
Then on your second computer you need to add a custom dns entry for these new domain names. If it is Windows, edit the file c:\windows\system32\drivers\etc\hosts. If it is Linux, edit /etc/hosts. Either way add:
10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com
Now on your second computer you should be able to access the following URLs:
http://development.myserver.com:50080
http://cms.myserver.com:50080

Unless I'm missing something, you'll need to either set up DNS entries, or add entries to the /etc/hosts file of each computer accessing the server.
localhost is an entry that exists in everyone's /etc/hosts file by default, always pointing to 127.0.0.1. Without adding a /etc/hosts entry, developer.localhost doesn't exist, and prefixing an ip address with a subdomain won't work at all.

Using a SSH + Putty tunnel, and thus having a 127.0.0.1 on my server, I managed to access my subdomains by doing the following on my server side:
# nano /etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com
I did not change the host file of the remote computer, and it works like a charm

For Named Virtual Hosts you need to use a hostname or domainname to connect to you apache server. It does not work with ips.
You could insert an entry in your /etc/hosts on your second system.

Related

Make local website available to all devices in local network

I have created a LAMP server and in there I host a couple of websites. These websites are currently available only when I access them from my Ubuntu machine. How can I modify the virtual hosts so that all the devices connected in the network can access these websites too ?
Websites' .conf file, located in /etc/apache2/sites-available/ looks like this:
Website1.com
<VirtualHost *:80>
ServerAdmin webmaster#website1.com
ServerName website1.com
ServerAlias www.website1.com
DocumentRoot /var/www/html/website1.com/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Website2.com
<VirtualHost *:80>
ServerAdmin webmaster#website2.com
ServerName website2.com
ServerAlias www.website2.com
DocumentRoot /var/www/html/website2.com/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The hosts file looks like this:
127.0.0.1 localhost website1.com website2.com
Both of these websites can be accessed from my Ubuntu machine by simply entering their names in the browser, but any other device in the network has no access to them.
You have to do two things.
1. Setup Apache virtual host
Virtual host must listen to your private IP, not localhost.
Find your private IP using ifconfig command in terminal and look for it in the output.
$ ifconfig
...
wlp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.88.11 netmask 255.255.255.0 broadcast 192.168.88.255
...
My private ip is 192.168.88.11
Virtual host must listen to it:
<VirtualHost 192.168.88.11:80>
Note! Maybe *:80 also works!
2. Setup DNS server in your local network.
Other machines in the local network must know where is the website1.com. DNS server must resolve website1.com to 192.168.88.11.
My router is MikroTik. And through the admin panel, using router's terminal, I can configure Static DNS of domains to resolve to internal ip.
/ip dns static add name=website1.com address=192.168.88.11
Also I can use regular expressions to match many domains using one static record.
Regular expression below matches all .lan domains: foo.lan, bar.lan, anysite.lan, etc.. And all of them will be resolved to 192.168.88.11.
/ip dns static add regexp=".+\.lan" address=192.168.88.11
You have to find out capabilities of your router to set it up.

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.

wamp server: set up virtual host

I am setting a virtual host with wamp server following this tutorial
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
hosts file
127.0.0.1 localhost
127.0.0.1 dev.gamenomad.com
httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "C:\wamp\www\dev.gamenomad.com\public"
ServerName dev.gamenomad.com
ServerAlias dev.gamenomad.com
ErrorLog "logs/dev.gamenomad.com-error.log"
CustomLog "logs/dev.gamenomad.com-access.log" common
</VirtualHost>
<Directory C:\wamp\www>
Order Deny,Allow
Allow from all
</Directory>
httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
I am unable to access dev.gamenomad.com . I got this error
i18n-values: Missing value for "primaryParagraph"
GET http://dev.gamenomad.com/ net::ERR_CONNECTION_REFUSED http://dev.gamenomad.com/:1
fyi, my apache server listen to port 8080 instead of the default 80. Does it affect my virtual host?
For wamp, you can set a virtual host using swamp UI as well. For that, you need to left-click on wamp icon -> Your Virtual hosts -> VirtualHost Management.
Then, just enter the server name, absolute path to the folder and then create the virtual host.
You can check it yourself here
Use gamenomad.git instead dev.gamenomad.com
And directory like Document root and goto c:\windows\system32\drivers\etc
Open the "hosts" file
And goto end line and type
127.0.0.1 gamenomad.git
Save change as administrator
End

Forwarding from subdomain to port not working

the problem:
I am running a Windows Vserver and on this server I'm running a standalone Grails app on port 8081, which means that when I open
localhost:8081 (local) or domain:8081
in the browser, I see the interface of the Grails app.
What I am looking for is a way to type
subdomain.domain
that forwards me to
domain:port
I have read that this can be done using a virtual host on Apache. I used the XAMPP Apache because I'm running XAMPP MySQL anyway.
I added this line to the WIndows host file:
127.0.0.1 subdomain.domain
and this part to apache/conf/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerName http://localhost
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost *:80>
ServerName http://subdomain.localhost
Redirect / http://localhost:8081
</VirtualHost>
What I expected:
when I open domain I see the xampp admin interface
when I open subdomain.domain I see the Grails app (as domain:port)
What happens:
no matter wheather I open domain oder subdomain.domain I'm always forwarded to domain:port
What am I doing wrong?
Regards
H
Solution (no idea where the technical difference is):
<VirtualHost Server-IP:80>
ServerName http://domain
DocumentRoot "C:/xampp/htdocs"
</VirtualHost>
<VirtualHost Server-IP:80>
ServerName http://subdomain.domain
Redirect / http://domain:port
</VirtualHost>
I even didn't have to make any entries in the Windows host file. NameVirtualHost wasn't necessary either.

Apache vhosts on localhost

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