Accessing localhost Webserver Over Network - apache

I am using my local machine as a development server. I have my hosts file set up as such:
127.0.0.1 localhost
127.0.0.1 cdog24
127.0.0.1 xxxxxorg
127.0.0.1 newintranet
My httpd-vhosts.conf file is set up as follows:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs"
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\cdog24"
ServerName cdog24
ServerAlias cdog24
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\xxxxxorg"
ServerName xxxxxorg
ServerAlias xxxxxorg
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:\Webserver\htdocs\newintranet"
ServerName newintranet
ServerAlias newintranet
</VirtualHost>
I am running xampp and can access each site on my local machine respectively by typing in:
http://localhost
http://cdog24
http://xxxxxorg
http://newintranet
When i go to a different computer on my network, I assume I have to type int he name of my machine or use the IP address. So, when I type in the following:
http://machinename/cdog24 or http://10.1.0.24/newintranet
I am taken to a 404 page.
What am I missing? Firewall on local machine or network do not factor as they are both off. I am on a Windows 7 local machine, the remote machine is also Windows 7.
Thanks for any help.

You will need to edit the hosts file on the remote machine (where the browser is running, not the server):
x.x.x.x cdog24
x.x.x.x xxxxxorg
x.x.x.x newintranet
Change x.x.x.x to the IP address of the Windows box that is running the server.
Now you should be able to browse to, say http://cdog24/ in your browser.
However, do NOT add a localhost entry that points to the other machine. localhost should always point to 127.0.0.1!

Have you tried with just http://machinename/ ?
http://machinename/directory would require that the document root be pointing to htdocs itself.

You need to work out what the IP address of your machine is on your network, and then edit teh hosts files on the other machines to point to yours
<your local IP> cdog24
<your local IP> xxxxxorg
<your local IP> newintranet
You maybe also have to update the apache conf file to work from your network address rather than 127.0.0.1.

Related

Create VirtualHost with DocumentRoot in another server

I have two server VM with centos 7. With IP public 103.x.x.78 and domain one.example.go.id
This IP local is 192.168.10.200 (Server A).
I created another one VM with IP local 192.168.10.103 (Server B). With planned to pointing my other domain two.example.go.id
This my configuration:
one.example.go.id pointing to 103.x.x.78
I have create VirtualHost with DocumentRoot /var/www/html and work.
Then
two.example.go.id pointing to 103.x.x.78
I try to open this domain worked. Open webpage.
Create /etc/hosts at Server A:
192.168.10.103 two.example.go.id
And create VirtualHost at Server B
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.two.example.go.id
ServerAlias two.example.go.id
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:443>
ServerName www.two.example.go.id
ServerAlias two.example.go.id
DocumentRoot /var/www/html
</VirtualHost>
I have access IP 192.168.10.103 or two.example.go.id in server A it load perfectly. But when I access with two.example.go.id in other device (Internet), it doesn't work. This site can't be reached.
Is there a step I missed?
*This my first question with poor english. CMIIW
Did you also add a /etc/hosts to the Server B? Because /etc/hosts works only on the device you have added it on. For example, if you add a /etc/hosts directive in Server A, it will only work for Server A. You have to add the same for Server B also.
Or, if you don't want to use /etc/hosts because of this, then you can setup a DNS server of your own in your local network.

Using a hostname on Apache rather than an IP

I am wanting to run a hostname on apache (on xampp) and I have changed the httpd.conf file so that ServerName example.com.
I then changed httpd-vhosts.conf so that
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot "C:/xampp/htdocs/example"
ServerName example.com
ErrorLog "logs/example.com.log"
CustomLog "logs/example.com.log" common
</VirtualHost>
and then added 127.0.0.1 example.com to the hosts file in the System32->drivers->etc folder.
It works on the computer running xampp (I think because that has the altered hosts file) but it will not work from other computers on the same network, which I gather is supposed to be handled by the virtual hosts file.

Xampp Apache Virtual Hosts Not Redirecting

I'm using the Xampp tutorial to set up virtual hosts. My httpd-vhosts.conf looks like this...
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/www/mysite/public_html"
ServerName mysite.com
</VirtualHost>
My hosts entry looks like this..
127.0.0.1 mysite.com
The hosts part is working because mysite.com lands me on the Apache dashboard (mysite.com/dashboard).
I have the Apache server on 8080, and can browse to my site manually with http://127.0.0.1/www/mysite/public_html/
I've tried the virtual hosts config with 80 and 8080.
How can I get it to land on my site?
Edit: On my console (checking syntax) # httpd.exe -t Syntax OK

Configurating apache vhosts to access domain from outside of local network

Configuration
I am running Windows Server 2012 with XAMPP installed in C:\xampp
Apache running as a Service
I have edited host file in C:\Windows\System32\Drivers\etc, added following
127.0.0.1 landing.local
I added vhost in C:\xampp\apache\conf\extra\httpd-vhosts.conf
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost landing.local:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
I also uncommented following line in httpd-vhosts.conf
NameVirtualHost *:80
and in httpd.conf
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include "conf/extra/httpd-vhosts.conf"
and Apache is configured to Listen on port 80.
Listen 80
Where landing.mydomain.com is redirected to Public Virtual IP from Windows Azure.
Problem
When I access locally http://landing.local/ site works
But when I try to access landing.mydomain.com from inside network it doesn't work, instead it redirects to main localhost site.
So I tried using landing.mydomain.com in hosts and landing.mydomain.com in vHost.
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
This time I am able to access landing.mydomain.com from inside network, on server but when I try to access it from outside local network it doesn't work.
I also tried editing host file and pointing landing.mydomain.com to my Public Virtual IP or Internal IP address. Didn't help...
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
Host file
255.255.255.255 landing.mydomain.com
Where 255.255.255.255 is my Public Virtual IP and 255.255.255.254 Internal IP but it didn't work. It would just open my localhost (homepage of mydomain.com)
255.255.255.254 landing.mydomain.com
Also I tried to
Bind Apache to Public Virtual IP 255.255.255.255 by editing httpd.conf
Listen 255.255.255.255:80
(OS 10049)The requested address is not valid in its context. : AH00072: make_sock: could not bind to address 255.255.255.255:80
AH00451: no listening sockets available, shutting down
Apache did work when I binded to Internal IP Address, but still I was unable to access landing.mydomain.com from outside the network, it again redirected to my homepage (server localhost)
Listen 255.255.255.254:80
I also received this warning when starting from dos, but it's not the cause of my problems, that's the line I uncommented from httpd.conf cause I read somewhere on boards it helped to some to solve their problems, didn't help me at all, same with commented and uncommented.
Host >>
127.0.0.1 landing.mydomain.com
With this configuration I was unable to access subdomain from localhost. I was still able from outside the network since it was redirect using A record to my server Public Virtual IP.
AH00548: NameVirtualHost has no effect and will be removed in the next
release C:/xampp/apache/conf/extra/httpd-vhosts.conf:19
Solution
So I changed the IP address in host file also to Internal IP Address, 255.255.255.254
255.255.255.254 landing.mydomain.com
And left the vhost as.
NameVirtualHost localhost:80
<VirtualHost localhost:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAlias localhost
</VirtualHost>
<VirtualHost landing.mydomain.com:80>
DocumentRoot "C:/xampp/htdocs/landing"
ServerName landing.mydomain.com
ServerAlias landing.mydomain.com
</VirtualHost>
If someone is familiar with configuration of Apache on Windows Server 2012 please any help is appreciated :)
Update
I forgot to mention you should not forget to configure Windows Server Firewall (allow on ports 80 and 443, tcp incoming traffic) as well as endpoints (tcp 80 and 443) on Azure platform.

Access Apache VirtualHost from any computer on LAN?

I have wamp setup with quite a few websites setup as virtual hosts like this in httpd.conf
<VirtualHost 127.0.0.1>
ServerName project1.local
DocumentRoot "c:/wamp/project1/"
</VirtualHost>
I have these input in the wamp machine's host file and I can access them just fine on that machine.
127.0.0.1 project1.local
However, when I try to put an entry on my OSX machine as (192.168.1.101 being the internal ip of the wamp machine) it won't pull the page up.
192.168.1.101 project1.local
Is there something else I need to do to make this work from other machines? Thanks!
You either need <VirtualHost 192.168.1.101> (in addition to 127.0.0.1), or simply use <VirtualHost *> to put the VH on all addresses.
Just add below code in your virtual host config file
In the below code,
'Client_IP' is the IP of the machine from where you want to access the directory without using any ip on the address bar, just put severname in the address bar like 'servername/'.
<VirtualHost *:80>
ServerName servername
DocumentRoot d:\wamp\www\dir_name
<Directory "d:\wamp\www\dir_name">
Order Allow,Deny
Allow from 127.0.0.1 Client_IP
</Directory>
</VirtualHost>
Then, set same servername that you have used for the virtual host on apache server like,
server_ip servername
in the client machine c:/windows/system32/drivers/etc/hosts file.