Access local domain from another machine in the same net work - apache

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)

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

virtual host subdomain not working properly, points me to main domain

<VirtualHost *:80>
ServerName db.mydomain.co
#ServerAlias db.mydomain.co
DocumentRoot /var/www/db/public
<Directory /var/www/db/public>
AllowOverride All
</Directory>
ErrorLog /var/www/db/error.log
CustomLog /var/www/db/requests.log combined
It's the config file I created in cong.d directory. I also changed the host file on my PC pointing mydomain.co to the server IP address. After I restarted my apache server, I go to db.mydomain.co which gives me db.mydomain.co’s server DNS address could not be found. But ironically, mydomain.co shows me the subdomain content and I won't be able to access the website hosted on my main domain. I'm using the distribution made by Amazon, and it's based on CentOS I think.
I really have no idea what's going on here. Any helps appreciated.

Wamp 2.5 local host doesn't work after I have setup virtual hosts I get 403 forbidden error

I have setup virtual hosts now when I type localhost it does not work I figured that now I'll have to make a virtual host for local host it self and it worked but now when I type my external ip it does not work it says 403 forbidden so how do i fix this do I have to make a virtual host for my external ip and will it work for everyone or just my computer for example if I give to a friend and he typed my external ip will it work?
When you create Virtual Hosts, Apache ignored the host defined in httpd.conf i.e. localhost. So you have to create a vhost for localhost as well.
For security it should be the first vhost defined, as if someone just tries your ip address, Apache will default to the first vhost and that will be defined with only local access and they will get an error saying you are not allowed in.
As per your other question, you should only be allowing access to your .tk domains if the user actually enters a valid xxx.tk domain name and disallow access if they just use your wan ip address.
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.0 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>

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

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