After setting up Apache virtual hosts with hostnames "server1" and "server2", how would I access them with my iPhone (or any mobile device) since there's no way modify the /etc/hosts file in iOS or Android?
My understanding is that you have to reference the virtual hosts by name (assuming you only have 1 IP address on your physical server), but there's no way to map those virtual hostnames to the single IP address on my physical server.
I'm running my server on my laptop using MAMP and my Vonage router/Apple Airport don't support DNS. Do I need to setup a local DNS server? Is there any easy way to run that on my laptop? Thanks.
Adding as following
httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "/opt/lampp/htdocs/api/www"
ErrorLog "logs/app_error"
CustomLog "logs/app_log" common
</VirtualHost>
httpd.conf:
Listen 80
Listen 8080
Then in your mobile you can use:
http://<your laptop address>:8080/
You can't if you don't have a local DNS.
As a workaround, you could setup your first VirtualHost to listen on the 80 port and the second one on the 81 (or 8080 or whichever ports you want) and access the server by using http://your.server.ip.addr:port.
You could use IP aliasing and configure IP-based virtual hosts. But then you have to access the sites via IP from your mobile device. But I guess using different ports as #Renaud suggests is easier.
If you want to do it, add an IP alias using ifconfig <interface> inet <ip> add on Mac OS X. Then add a Listen <ip> and <VirtualHost ip> directive to your Apache configuration.
The below link has a nice work around for this problem.
Pleas go through this, after you have set the virtual host.
1.http://rocketmodule.com/blog/easy-and-free-way-test-local-sites-ipads-iphones-and-other-mobile-devices/
but instead of the path you need to give the local domain name. for example "king.dev" link below
192.168.1.250(your system ip) king.dev
in the hosts.ics file in your system.
now you can access the website from your mobile typing in your browser like.
192.168.1.250:4000[if you have set the port]/your_file.html
your local website will be displayed in the mobile device
you can also have a look at
http://www.tech-otaku.com/local-server/accessing-localhost-virtual-hosts-network-computer/
Related
I want to access my virtual hosts (websites) that I've set up in my VirtualBox -> Ubuntu-Server 18. I have apache2 installed and everything is setup.
The host machine (macOS) can presently gain access to the default website of apache2 in the guest (Ubuntu-server) through a Port Forwarding rule I have assigned in the VirtualBox Network Settings:
127.0.0.1:8000 -> 10.0.2.15:80
I've set up a virtual host in my guest machine with the following configuration:
<VirtualHost *:80>
ServerName dropn.taxi
ServerAdmin admin#dropn.taxi
DocumentRoot /var/www/dropn.taxi/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The DocumentRoot directory mentioned above exists and has the files necessary to serve a basic "Hello World" home page. I've tested it with my apache installed in my local machine as well. The website's not the problem.
But everytime I access localhost:8000 from the local machine, I'm greeted with an Ubnutu-Apache greetings page. Whereas when I try localhost:8000/dropn.taxi, I get a 404 page. I've researched quite a bit and the closest I can get to a solution is what is suggested in this page:
Ubuntu Apache2 local virtual hosts url not found
Simply put: How can I access virtual hosts of the guest machine (VM) from the host machine?
Still not specific to my case. Would appreciate any help in this regards.
localhost in the apache2 server is set to point to /var/www/html by default. For the virtual hosts to work properly, the domain name accessing them must be what is defined in the ServerName field.
localhost:8000/dropn.taxi would translate to 127.0.0.1/dropn.taxi in the VM guest. Which means, it is trying to access the /var/www/html/dropn.taxi, which, ultimately does not exist, hence the 404 error.
The solution to this is to add dropn.taxi to the /etc/hosts file in both the Host Machine and the VM. The line would look like:
127.0.0.1 localhost dropn.taxi
While accessing from the Host Machine, we use dropn.taxi:8000 in the browser whereas the port :8000 is not used in the guest machine. This way, whenever accessing the virtual hosts, the domain name accessing them matches the ServerName field and it simply works!
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
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
I have added a virtual host container in my httpd.conf file.
<VirtualHost *:80>
DocumentRoot /var/www/dev_sites/site
ServerName site.aa.local
</VirtualHost>
In my /etc/hosts file on my server computer it is:
127.0.0.1 site.aa.local
If I go to site.aa.local on my machine I can see my site. However if I go to that same address on another computer on my network it doesn't find the page. However, if I do aa.local it finds that. Any idea why a computer on my network can't see it?
I'm on a centos machine.
site.aa.local points to your loopback interface in your machine. Just in case: it's a virtual interface that is only accessible from your machine by definition.
For that name to work in another computer, site.aa.local should point to your machine's LAN IP address (either via /etc/hosts or DNS) and the Apache server in your computer should be listening in all interfaces (it most likely is).
Try adding YOUR_LAN_IP site.aa.local to the /etc/hosts file in the other computer, or just visit YOUR_LAN_IP if that is the Apache default virtual host (that is, if it's the only one or the first defined).
These two machines A and B are NAT behind 1 IP address.
Url.xyz.com goes to machine A on port 80 served by apache 2.2
and url2.xyz.com is supposed to go to machine B on port 80 served by apache 2.2 on that machine
i have machine A taking all inbound port 80 packets from my gateway...fyi
at one point i had apache on machine A setup to do this, but now i am struggling
to regain the good config. I am using a diff OS on a diff Machine B for good reasons....
i recall setting up virtual server url2.xyz.com in apache 2.2 on machine A using
port 80, then setting the host file on machine A and B to have a line titled:
192.168.0.x url2.xyz.com url2
and setting the document root for url2.xyz.com in apache on machine A equal to the document root on machine B. (it won't take a blank field....)
I am either dreaming, or missing a slight setup step. Any help appreciated. As I recall, from about six months ago, it seemed that apache on machine A read the host file and did this right..
the net good result is (hopefully) that the virtual server on machine A gets content from machine B (or C, or D, etc...)
alternatively i will try to get another Ip address from my provider.
One possibility is to have machine A act as a proxy for machine B. Meaning all requests for both domains go to machine A on port 80, but then you set up name based virtual hosts in apache. The virtual host for url2.xyz.com then forwards on the request to machine B.
Something like this:
Virtual hosts on machine A:
<VirtualHost *:80>
ServerName url1.xyz.com
DocumentRoot /var/www/url1
</VirtualHost>
<VirtualHost *:80>
ServerName url2.xyz.com
ProxyPass / http://url2.machineB/
ProxyPassReverse / http://url2.machineB/
</VirtualHost>
And then on machine A you define url2.machineB to point to the IP address of machine B. You do this by adding a line to the file /etc/hosts. Then on machine B you create an apache virtual host to listen for that domain, like so:
<ViirtualHost *:80>
ServerName url2.machineB
DocumentRoot /var/www/url2
</VirtualHost>
This might not be exactly the solution, but should give you one option to take. See http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for more on proxying.