Reputation: 321
I'm creating an android app that uses 2 virtual hosts. One for the api and one for the repository of all the images uploaded in my app. I can access one of them without using virtual hosts and through my laptop's IP address only. But I want to access them both through virtual hosts so that I dont have to change it when I upload it to the live server. Please help me how to do it.
Here's the snippet of my XAMPP "httpd-vhosts.conf" file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myprojectapi"
ServerName api.mydomain.com
ServerAlias api.mydomain.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myimages"
ServerName images.mydomain.com
ServerAlias images.mydomain.com
</VirtualHost>
and heres the snippet of my windows "hosts" file:
127.0.0.1 api.mydomain.com
127.0.0.1 images.mydomain.com
I can only access one of them from my android phone but only through my laptop's IP address and if i comment out one of the vhosts:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myprojectapi"
ServerName api.mydomain.com
ServerAlias api.mydomain.com
</VirtualHost>
#<VirtualHost *:80>
# DocumentRoot "C:/xampp/htdocs/myimages"
# ServerName images.mydomain.com
# ServerAlias images.mydomain.com
#</VirtualHost>
and my hosts file:
127.0.0.1 api.mydomain.com
#127.0.0.1 images.mydomain.com
but in order for my app to work properly i need to access the two projects through Named Virtual Hosts at the same time. What should I do to make this work? Please help.
UPDATE:
Im already using different ports but it still won't work.
Here's the snippet of my updated vhost file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myprojectapi"
ServerName api.mydomain.com
ServerAlias api.mydomain.com
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot "C:/xampp/htdocs/myimages"
ServerName images.mydomain.com
ServerAlias images.mydomain.com
</VirtualHost>
and heres the snippet in my updated hosts file:
192.168.2.5 api.mydomain.com
192.168.2.5 images.mydomain.com
Upvotes: 0
Views: 4633
Reputation: 3855
If you want to get access to your Virtual Hosts inside emulators (like GenyMotion or any other) follow bellow steps:
1: Open up httpd.conf
file
2: Choose different ports for your different virtual hosts and make sure to add Listen ****
there
Listen 80
Listen 8081
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/myprojectapi"
ServerName api.mydomain.com
ServerAlias api.mydomain.com
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot "C:/xampp/htdocs/myimages"
ServerName images.mydomain.com
ServerAlias images.mydomain.com
</VirtualHost>
3: Save the httpd.conf
file and restart your apache
services.
4: Open the browser in your emulator and go to http://10.0.2.2:8081/
you will see your images.mydomain.com
there :)
Upvotes: 2