I am using Windows 7 with Wamp 2.2 server.
I have setup 2 virtual hosts: www.project1.com and www.project2.com.
I have modified the "hosts", the httpd.conf, and the httpd-vhosts.conf files, to the changes I mentioned below.
Using my browser, when I type www.project1.com or www.project2.com, I successfully get my web pages opened on the laptop that has the server installed on.
Changes in the "hosts file": I've appended the followings to the end of the file:-
127.0.0.1 localhost
127.0.0.1 www.project2.com
127.0.0.1 www.project1.com
Changes in the httpd.conf file:-
Include conf/extra/httpd-vhosts.conf
Changes in httpd-vhosts file:-
NameVirtualHost *:80
<Directory "D:/websites/">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/wamp/www/"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "D:/websites/project2/"
ServerName www.project2.com
</VirtualHost>
Now; since I can open these web pages from a browser in PC_1 (the one with the server), how can I access these web pages from a browser in PC_2? (I mean any PC connected to PC_1 via LAN.)
In addition to danp's answer, you can access the virtual host without having to change the client machine's etc/hosts file by assigning a port to the virtual host. This is ideal if you want to access the server with a mobile or tablet device:
Edit server's httpd.conf file at:
\wamp\bin\apache\apache2.2.x\conf\httpd.conf
Search for "Listen" (around line 61). You should see the following that allows for Apache to listen for port 80:
Listen 0.0.0.0:80
Listen [::0]:80
Add the following lines to add listening for port 81 (or any port):
Listen 0.0.0.0:81
Listen [::0]:81
Edit the httpd-vhosts.conf file at:
\wamp\bin\apache\apache2.2.x\conf\extra\httpd-vhosts.conf
Change your "Virtual Host" tag to port 81:
<VirtualHost *:81>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
Restart Apache server.
On the client machine/tablet/mobile, on the web browser, enter the server's IP address (192.168.0.10, or whatever IP) followed by the port number in the following format:
http://192.168.0.10:81
In your virtualhost directive, change 127.0.0.1 to *:80 and as Gabriel mentioned, add an entry to the hosts file in the other machine, adding your domain to be associated with the IP of your server.
When you put an explicit IP into the directive, apache will only listen on that IP - but the wildcard will tell it bind to all IPs available to it.
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
If your server is on 192.168.1.70 for example, then in the other machines on your lan, the hosts entry will look like:
192.168.1.70 www.project1.com
Restart apache and it should work fine.
As a note, when you are using virtualhosts, apache will use the first definition as a default for when it can't make a match between the domain passed in the HTTP request header and the sites setup in the config, which is why your default page was appearing.
You told apache to bind to all IPs with the NameVirtualHost *:80 directive, but then didn't setup a site for that external IP. Hope that helps!
There are two computer in local network.
A computer(192.168.1.70) Setup(D:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf):
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
ServerName www.project1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/websites/project2/"
ServerName www.project2.com
</VirtualHost>
B computer Setup(c:/windows/system32/drives/etc/hosts):
192.168.1.70 www.project1.com
192.168.1.70 www.project2.com
B access A,My project is working.
A couple of updated points to consider for the selected answer:
NameVirtualHost is no longer used after Apache version
2.3.11 and can be omitted.
In 2.3.11 and later, any time an IP address and port combination is
used in multiple virtual hosts, name-based virtual hosting is
automatically enabled for that address.
Because we are talking about hosting a website over LAN, let's set a
requirement* to only accept connections from IP addresses on your
local network. For example, on a common Linksys router, the default
IP assigned to each device on the network is between 192.168.1.100
to 192.168.1.255. You can allow connection from all devices on the
LAN with an IP address 192.168.1.XXX by using Require ip 192.168.1
(notice the final octet is left off the IP to allow the entire
range).
This allows you to configure access per project so that one may be
available over LAN and another is only available locally.
# This will allow all LAN connections to www.project1.com
<VirtualHost *:80>
DocumentRoot "D:/websites/project1/"
<Directory "D:/websites/project1/">
Require local
Require ip 192.168.1
</Directory>
ServerName www.project1.com
</VirtualHost>
# This will allow only the machine hosting the website to access www.project2.com
<VirtualHost *:80>
DocumentRoot "D:/websites/project2/"
<Directory "D:/websites/project2/">
Require local
</Directory>
ServerName www.project2.com
</VirtualHost>
While your site will not be served publicly without the router forwarding traffic on port 80 to your host, I believe this is considered best practice. It is especially necessary if you need to control which projects are available to devices on the LAN.
Reminder: Your host machine should be configured to use a static IP address
instead of being assigned one by your router's DHCP. Since we are
editing the hosts file of other devices to point to the server's IP,
we don't want it to change.
* I'm including this because it is common to have access restrictions on a local development server and you will need to specifically make it available to your local network.
You need to change the hosts file on the machine you're trying to view the page from.
So you need to add them to the hosts file on the other lan machine.
if you are not able to access your virtual host server in your local area network then check you have configured your firewall to allow httpd.exe file (lying in folder C:\wamp64\bin\apache\apache2.4.51\bin) to allow both incoming and outgoing connections
Related
I am having a website first.com which is deployed on a windows server with ip like (11.111.111.11) using 80 port (DNS is pointed on first.com of host server), Now I have installed Xampp and run on 8081 port and deployed code which can be accessed using ip 11.111.111.11:8081/second, what I have to do is another domain second.com to point this second folder of xampp so second.com is equals to 11.111.111.11:8081/second, I have changed DNS of second.com to host DNS of first.com as it is done for this domain.
And changed my vhost of xampp like
<VirtualHost *:8081>
DocumentRoot "D:/xampp/htdocs"
ServerName www.second.com
<Directory "D:/xampp/htdocs/second">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now when I am hitting this second.com it points the same website of first.com but when I hit second.com:8081/second it points to the new website which logically is working fine, now I want that second.com should open the new website without showing any port/folder.
I believe it is Possible, Please suggest.
Thanks in advance
I think you maybe enabled the virtual host on the xampp,
then you can do the domains pointed to same port by editing the file /httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/website_a
ServerName www.website_a.com
ErrorLog "/opt/lampp/htdocs/website_a/error_log"
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/website_b
ServerName www.website_b.com
ErrorLog "/opt/lampp/htdocs/website_b/error_log"
</VirtualHost>
If you want to know more some reference, here is one for you:
https://github.com/oliguo/Server-Deployment/blob/master/XAMPP.md
may I ask question about the Apache Virtual Host config?
I use XAMPP, and my ipv4 is 192.168.1.7
I have configured my host file (C:\Windows\System32\drivers\etc...) like
127.0.0.1 g4.org
192.168.1.7 g4.org
and C:\xampp\apache\conf\extra\httpd-vhosts.conf like
NameVirtualHost 192.168.1.7:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/rs"
ServerName g4.org
ServerAlias www.g4.org
</VirtualHost>
The virtualhost works perfectly on the machine that has installed xampp .
but the problem is in the another machine(PC) [SAME LAN] if i go to http://192.168.1.7 the page load and work perfectly
but
if i go to this link http://g4.org the page won't load and say
ERR_CONNECTION_REFUSED
In the another machine, just put the "192.168.1.7 g4.org" at the host file.
this is a situation that's been bugging me a lot the past few days. i have a lot of dev environment subdomains set up in my etc/hosts file like so...
127.0.0.1 localhost
127.0.0.1 sub.localhost
127.0.0.1 another.localhost
127.0.0.1 andanother.localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
and then specified in my Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file, like so...
NameVirtualHost *:80
NameVirtualHost sub.localhost:80
NameVirtualHost another.localhost:80
NameVirtualHost andanother.localhost:80
<VirtualHost *:80>
DocumentRoot "/Users/johndoe/websites"
ServerName localhost
</VirtualHost>
<VirtualHost sub.localhost:80>
DocumentRoot "/Users/johndoe/websites/sub"
ServerName sub.localhost
</VirtualHost>
<VirtualHost another.localhost:80>
DocumentRoot "/Users/johndoe/websites/another"
ServerName another.localhost
</VirtualHost>
<VirtualHost andanother.localhost:80>
DocumentRoot "/Users/johndoe/websites/andanother"
ServerName andanother.localhost
</VirtualHost>
and just recently they all stopped working in Chrome (Firefox & Safari worked just fine). i started getting 404 errors for all of my localhost subdomains.
editing/changing the settings in etc/hosts didn't work
editing/changing the settings in my httpd-vhosts.conf file didn't work
i just couldn't figure out why Chrome was not resolving those addresses to those directories on my local machine.
.
after a lot of research (and trial and error) i realized it was a DNS issue. previously, my DNS settings in System Preferences > Network > Advanced... > DNS > DNS Servers were as follows...
8.8.8.8
8.8.4.4
xxx.xxx.xxx.x
xxx.xxx.xxx.x
that's Google's DNS servers in the first 2 slots and the x's representing my ISP's DNS server addresses. after some searching some people recommended adding my local network's IP address first, as a way of forcing anything on my system to look locally first before going to outside DNS, so i added my network router's address above the others...
10.0.1.1
and that didn't quite work either - or it did - but didn't last (honestly can't remember now), but what i tried next actually DID work. i added my machine's localhost (home) address above the local network's address, like so...
127.0.0.1
10.0.1.1
8.8.8.8
8.8.4.4
xxx.xxx.xxx.x
xxx.xxx.xxx.x
.
and NOW Google Chrome successfully "finds" all of my localhost subdomains.
i sure hope all of this is helpful for others out there.
This bugged me too just recently. It was working fine then all of a sudden it stopped.
I put my router's ip address (192.168.0.1) first on the DNS Server.
I want to create a virtual host for my application i got some tutorials of how to setup a virtual host but still i am having issues with it, first i create a new file in the /etc/apache2/sites-avalable/popinbay.dev This is the popinbay.dev file please note that i am using ubuntu 14.04
<VirtualHost *:80>
ServerAdmin udemesamuel256#gmail.com
ServerName popibay.dev
DocumentRoot /var/www/laravel4
</VirtualHost>
then i edited the /etc/hosts and added this line
127.0.0.1 popibay.dev
then i did a sudo service apache2 reload based on this tutorial virtual host in ubuntu not work
But the problem is it still goes to the default localhost page instaed of the laravel4 page.
You are using a "Name-based Virtual Hosts".
From Apache docs on Using Name-based Virtual Hosts:
To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive. In the normal case where any and all IP addresses on the server should be used, you can use * as the argument to NameVirtualHost.
Try add NameVirtualHost *:80 to the top of your configuration, then restart your apache. E.g.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin udemesamuel256#gmail.com
ServerName popibay.dev
DocumentRoot /var/www/laravel4
</VirtualHost>
Note that you might need to change your DocumentRoot to /var/www/laravel4/public. That's where your http server should point to by default in Laravel projects.
You added virtual host file in sites-available folder but didn't Enabled it.
Use
sudo a2ensite virtuatl_host.conf
In your case,
sudo a2ensite popibay.dev.conf
And then,
sudo service apache2 reload
I am running XAMPP 1.7.3 on windows 7. My problem is that when I try to access my server (localhost) from another computer, the server does not respond. For example, [on my computer] when I type in 'http://localhost', my pages come up. However, when I try accessing 'http://192.168.0.102' from my computer, nothing happens. When I type in my external IP, nothing shows up, but when add HTTPS to the external IP, my Linksys WRT54GS config page shows up, asking for a password. I have already tried port forwarding and a local "static IP", and no luck, other than my local IP never changing. Can anyone help me?
Here's how I have my XAMPP installation configured. Maybe it will work for you.
Open C:\xampp\apache\conf\extra\httpd-vhosts.conf
Add a VirtualHost block for each site you are running:
Apache config
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot C:/path/to/website/files
ServerName exampledomain.dev
<Directory "C:/path/to/website/files">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add a line to your hosts
127.0.0.1 exampledomain.dev
On the connecting computer's host file:
192.168.0.102 exampledomain.dev
You can easily access your hosts file by using ctrl+r and running
notepad %SYSTEMROOT%\system32\drivers\etc\hosts