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

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

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

Accessing Virtual Hosts Across a Local Network

I've 2 machine on my local network. On my first machine A, i've creat a vhost mysite.lan and i want access to this vhost with my machine B.
If i don't edit my host file, i do not access.
Do you know if i can access on my vhost without edit my host file ?
My vhost :
<VirtualHost *:80>
ServerName wordpress.lan
ServerAlias www.wordpress.lan
DocumentRoot /var/www/html/www.wordpress.lan/webroot/
ErrorLog /var/www/html/www.wordpress.lan/logs/error.log
CustomLog /var/www/html/www.wordpress.lan/logs/access.log combined
</VirtualHost>
Thank you !
You'll need something on your network to read these requests and forward them to the correct address - in the absence of anything else an entry in the hosts file will do this.
Your router contains DNS servers, either entered manually or populated by your internet service provider. By default, these servers provide lookup information for DNS queries. You can run a DNS server locally, but it's a lot of work to achieve what you're looking for.
See this link for info on doing this on Linux (I'm not sure what OS you're on, but I assume it's either Mac or Linux based on format of your vhost entry):
https://superuser.com/questions/45789/running-dns-locally-for-home-network

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

Apache: see named virtual hosts from LAN

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

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