Apache: see named virtual hosts from LAN - apache

I use some Virtual Hosts on Apache to speed up development. My configurations look like this:
<VirtualHost 127.0.0.1>
ServerName my_server.dev
DocumentRoot "my_root"
<Directory "my_public_files">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName another_server.dev
DocumentRoot "another_root"
<Directory "other_public_files">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
and so on. I also add myserver.dev and another_server.dev to the hosts files, so putting one of those address into the browser takes me to my development environment.
For testing purposes. I would like to be able to access these Virtual Hosts from ohter machines on my LAN. I can access the main Host just by putting the server local IP, but I don't know how to access other Virtual Hosts.
I think I could do this by assigning a different port to each Host, but this becomes uncomfortable after a while. Any chance to access the Virtual Hosts by name on the LAN?

You have to modify the hosts file on all computers in your LAN, so that they know that another_server.dev should directed to your local server. Otherwise, dns lookup will be made and fail as the domain doesn't really exists.

You must access the server by name, not by IP.
so, machines on you LAN should to know, where is the "another_server.dev", therefore you have to add into hosts-file line like:
10.0.0.1 another_server.dev my_server.dev
(replace 10.0.0.1 with your machine IP)
after this the machines on LAN can access your server with http://my_server.dev

Related

WAMP Server cannot be accessed through local network [duplicate]

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.
My setup and coding is pretty much this except with a different site title
wamp server 3.0 virtual host on another device
and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.
Has anyone managed to get mobile devices fully accessing links other than on localhost?
Since I posted the answer you referenced, I have decided upon a simpler solution.
What the actual problem is
Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.
If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.
192.168.0.10 example.local
But you cannot do that on a phone/tablet.
What Apache expects to be able to asssociate a request to a Vhost
When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.
But if we use for example example.local as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.
The simplest way to get round this is:
Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.
The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.
So how do we do this
Add the new listening port to httpd.conf like so after the 2 existing Listen statements
WAMPServer 3: Do this using the menus, not by doing a manual edit on httpd.conf
right click wampmanager-> Tools -> Add listen port for Apache
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000
Suggested httpd-vhosts.conf file
#
# Virtual Hosts
#
# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# The normal Vhost definition for one of our sites
<VirtualHost *:80>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# Access example.dev from phone for testing
<VirtualHost *:8000>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
# assuming yoursubnet is 192.168.0.?
# allow any ip on your WIFI access
Require ip 192.168.0
</Directory>
</VirtualHost>
Restart Apache from wampmanager after completing these edits.
Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000
Apache will find the correct code to serve from both requests.
If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.
You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

Access local domain from another machine in the same net work

I use local domain like this below.
/etc/hosts
127.0.0.1 my.koala.com
for apachec setting
httpd.conf
<VirtualHost *:80>
ServerName my.koala.com
DocumentRoot /Users/whitebear/CodingWorks/httproot/my/public
<Directory /Users/whitebear/CodingWorks/httproot/my/public>
Require all granted
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
Now I want to access this from the mobile in the same network.
My local pc ip is 192.168.2.127
Is it possible to access??
Or what is the good practice for this environment??
You could perhaps modify hosts file on the phone to point your domain name to 192.168.2.127.
If you have local DNS server in your network, you coould add A record that would point your domain name to that ip address, but that would then affect all devices on your network. (also, you probably want to make sure that your IP address is fixed so you don't have to modify DNS each time address changes)

Apache virtual host set up for remote access

I set up a virtual host on computer A by doing this:
Open apache config file (httpd.conf), insert lines as below:
<VirtualHost 127.0.0.1:80>
<Directory "{$path}/www/design-report/public/">
Options Indexes FollowSymLinks
AllowOverride FileInfo
Order deny,allow
Allow from all
</Directory>
ServerName weeklyreport.abc.com
ServerAlias www.weeklyreport.abc.com 127.0.0.1
DocumentRoot "{$path}/www/design-report/public/"
</VirtualHost>
Then I added a line as below to system32/drivers/etc/hosts:
127.0.0.1 weeklyreport.abc.com
By now on computer A I'm able to access weeklyreport.abc.com just into the right folder. I want to access this address from another computer named B.
So I changed the hosts file on B by adding A's IP like this:
192.xxx.5.xx weeklyreport.abc.com
Now I can access weeklyreport.abc.com from computer B.
But the problem is, it isn't the right folder. By this IP I can only access {$path}/www, not "{$path}/www/design-report/public/".
How can I fix this? Did I miss anything?
You missed the fact that VirtualHost definition tells apache to make virtual host only on given IP. It doesn't match for the external IP. You either need to defined second virtual host or use NameVirtualHost. For more details see Apache docu
HTH,Jan

How to use xip.io with several virtualhosts and server names? (local dev)

Is it possible to use xip.io to access local website when using virtualhosts with different server names? (I'm on linux, fedora).
For instance, let's say I have 3 websites I can access locally like so:
- http://localsite1
- http://localsite2
- http://localsite3
I would like to access them with other devices via xip.io:
- http://localsite1.192.168.0.15.xip.io
- http://localsite2.192.168.0.15.xip.io
- http://localsite3.192.168.0.15.xip.io
I can't figure out how to make this work, is it even possible?
Yes, it should be possible. I think you can have as many localsite domains as you want to manage. Check your hosts and httpd-vhosts.conf files.
A server alias in my /etc/apache2/extra/httpd-vhosts.conf works for me. I use a * instead of the current IP in my Network Preferences.
Remember to restart the Apache server after you make a change.
For example, my current local IP from the Mac OS System Preferences > Network says: Wi-Fi is connected to Workalicious2011 and has the IP address 10.0.1.118.
So my /etc/apache2/extra/httpd-vhosts.conf file has the following:
# Ensure that Apache listens on port 80
Listen 80
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Users/davekaplan/Sites/workalicious.com"
ServerName dev.workalicious.com
ServerAlias dev.workalicious.com.*.xip.io
ErrorLog "/private/var/log/apache2/dev.workalicious.com-error_log"
CustomLog "/private/var/log/apache2/dev.workalicious.com-access_log" common
</VirtualHost>
And my /etc/hosts file has:
##
Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 dev.workalicious.com
On my local network I am able to browse to the following and see my local development site:
http://dev.workalicious.com.10.0.1.118.xip.io/
I have a similar problem where I'm working on one mac and want to test on computers and other devices. Using .xip.io works great when you don't have access to a hosts file, on say a tablet.
If you have access to your hosts file on the computer you can add the IP of the local development host computer and just browse to the same url. It's great for PCs or other Macs. For example, I would add 100.0.1.118 dev.workalicious.com to the testing computer's hosts file and as long as I'm on the local network I can browse to dev.workalicious.com on that testing computer and see the site hosted over on the development computer.
Another approach that I used before .xip.io is Charles, it works great and there are some good blog posts out there on how to setup. It's currently $50 for a 1-4 Users.
( I'm working on try to figure out how to use Pow and Apache for a similar approach, but I don't think it works outside the local development machine. )
for me, server alias work.
ex:
<VirtualHost *:80>
<Directory "/home/michelangelo/www/mysite">
Options Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ServerAdmin michelangelo#mystie.com
DocumentRoot /home/michelangelo/www/mysite
ServerName mysite.local
ServerAlias mysite.local.192.168.0.6.xip.io
ErrorLog /home/michelangelo/public_html/logs/mysite_error_log
CustomLog /home/michelangelo/public_html/logs/mysite_access_log common
</VirtualHost>
tested on lubuntu
I was working on my project today and got stuck for a while but I've found a really easy setup which works like a charm.
You setup your virtualhost as you used to (do not have to use the alias xip.io at all tried it today)
Here comes the interesting part, when you edit host hosts file, enter your assigned local IP number before your domain name, e.g. 192.168.10.110 myawesomewebsite.com - which you can access at myawesomewebsite.com.192.168.10.110.xip.io

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