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.
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
So, i have a little issue here, i installed XAMPP which uses Apache on a Ubuntu desktop Virtual machine(on vbox), i also created a Laravel project on it and it works fine when i access it from the same VM itself !
Accessing the home page from firefox ubuntu
however when i try to access it from my host windows machine it just access to the XAMPP home page like this :
access from chrome windows
now my ubuntu VM has its address set to 192.168.1.50 and my windows 192.168.1.8 !
i also added to the windows machine "etc" file the entry :
192.168.1.50 usthbcloud.com
and to my ubuntu machine:
127.0.0.1 usthbcloud.com
my httpd.conf file of the XAMPP includes the file : httpd-vhosts.conf
i modified the httpd-vhosts.conf to the following :
vhosts.conf
Any solutions ?..
You're Facing issues in windows. Try this
<VirtualHost *:80>
DocumentRoot "D:/XAMPP/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/XAMPP/htdocs/eduguru/public/"
ServerName eduguruacademy.com
</VirtualHost>
Try this in your httpd-vhosts.conf. Replace with your DocumentRoot & ServerName Accordingly. Then restart XAMPP
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 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
I am trying to setup my dev machine with virtual hosts so I can access my development projects with a simple url, like http:// project.dev/ rather that a whole http:// 127.0.0.1/dev/path/to/root/of/project/ type of url.
Now, I'm aware there are many tutorials and questions already answered about this, but after trying many of them, I feel like I'm running in circles here.
The problem is simple: after setting up my hosts file and my virtual hosts, any attempt to access a virtual hosts irremediably displays the content of my server DocumentRoot.
my hosts file:
127.0.0.1 localhost
127.0.0.1 mydomain.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
my httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/
</Virtualhost>
<VirtualHost *:80>
ServerName mydomain.dev
DocumentRoot /Users/pilot/Sites/devel/vytamin/dev/
</VirtualHost>
I precise that the httpd-vhosts.conf file IS loaded in my httpd.conf and I do get a warning if I point the virtual host document root to a wrong folder.
I made a try setting the localhost virtual host to the following, without any success.
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Users/pilot/Sites/devel
</Virtualhost>
The following URLS all display the DocumentRoot of my server defined in my httpd.conf file, and seem to ignore the DocumentRoot defined in my VirtualHosts.
http:// 127.0.0.1/
http:// localhost/
http:// mydomain.dev/
I'm running Apache2.2 on Mac OSX 10.5 Leopard, but not the one shipped with mac os. I compiled my own under /usr/local/apache2 and web sharing IS disabled
I can't see anything wrong with my set up so I hope the community will!
Thanks for your help!
Ok, I found the problem!
The configuration above is perfectly fine, it was just that my apache was not restarting properly.
Neither apache_ctl graceful or apache_ctl restart was terminating all httpd processes I have running, therefore failing to reload properly the changes in my configuration files.
Once I killed the remaining processes and really restarted apache, it worked...
Solved, but I feel dumb to have found that!
Now I have a daemon situation to solve!