Access Apache VirtualHost from any computer on LAN? - apache

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.

Related

Xampp unable to load multiple sites

I am working on a project using xampp server. I have more than one project. So for this I have set my httpd-vhosts like below
<VirtualHost *:8080>
ServerName khpos.com
ServerAlias www.khpos.com
DocumentRoot "D:/xampp/htdocs/pos"
<Directory "D:/xampp/htdocs/pos">
Require all granted
</Directory>
</VirtualHost>
#my second site
<VirtualHost *:8080>
ServerName demopos.com
ServerAlias www.demopos.com
DocumentRoot "D:/xampp/htdocs/demopos"
<Directory "D:/xampp/htdocs/demopos">
Require all granted
</Directory>
</VirtualHost>
Whenever I try to hit localhost:8080/demopos it's redirecting towards .../pos
hosts file
127.0.0.1:8080 khpos.com
127.0.0.1:8080 demopos.com
How to set it
Any help would be highly appreciated
You should change the portnumbers of the second etc. sites. Now all port addresses are on port 8080, if you change those to an other port number you should be fine.
<VirtualHost *:8080> to <VirtualHost *:{port-number}>
Where port-number is an other port-number
127.0.0.1:8080 khpos.com
127.0.0.1:{port-number} demopos.com
you have 2 virtual hosts defined and also the names in hosts file. Please first remove the port numbers in the hosts file:
ServerName khpos.com
ServerName demopos.com
127.0.0.1 khpos.com
127.0.0.1 demopos.com
if you call khpos.com:8080 or demopo.com:8080 it should reach your correct virtual hosts.
But: if you call localhost:8080 it will match none of your virtual hosts.
In that case Apache always enters the first virtual host matching the port that you have in your conf file ignoring its server name. That is a strange behavior of Apache - in my opinion a bug. It is exactly what you observe.
For that reason I always place a dummy virtual server in front of all others that can catch all non fitting requests with a dummy message in a simple html file.
Just a hint: you have defined
DocumentRoot "D:/xampp/htdocs/pos"
so there currently is no khpos.com:8080/pos because pos is part of the root unless you create another folder pos below

Create a Virtual Host in Xamp Windows 10

Last night I have updated my windows 7 to windows 10.
The result is struggle trying to run my local apache server in windows 10 that is running on windows 7.I have tried uninstalling and installing another versions of xampp then I came up that I have to change the apache's default port just to make it run.
I changed httpd.conf
from Listen 80 to Listen 1234
AND
ServerName localhost:80 to ServerName localhost:1234
and in xampp control panel Config->Service and Port Settings. I also change the Main Port
Now I can access phpmyadmin using localhost:1234/phpmyadmin.
And now my problem is creating Virtual host
so I added in my host(C:\Windows\System32\drivers\etc\hosts) file
127.0.0.1 sample.local
127.0.0.1 anothersample.local
And my vhost (D:\xampp\apache\conf\extra\httpd-vhosts.conf) file
<VirtualHost *:1234>
DocumentRoot "D:/xampp/htdocs/sample"
ServerName sample.local
</VirtualHost>
<VirtualHost *:1234>
DocumentRoot "D:/xampp/htdocs/anothersample"
ServerName anothersample.local
</VirtualHost>
I did make sure the vhost file above was include
I already restarted my apache but seems like my vhost is not working .Can anyone point out what i missed?
Thank you #ShamSUP AND #maytham-ɯɐɥıλɐɯ I was able to solve my problem by uninstalling the xampp.
Then following the instructions here
I will just list the steps I have done here.
Windows+R and type appwiz.cpl and use Turn Windows features on or off and install the IIS Manager Console by expanding
Internet Information Services->Web Management Tools->then checking IIS Management Console
Windows+R and type InetMgr.exe and enter, then expand Site Right Click it then click Edit Bindings
Change the http port from 80 to 8080
After that I then install the XAMPP and configure the Virtual host
host(C:\Windows\System32\drivers\etc\hosts) file
127.0.0.1 sample.local
127.0.0.1 anothersample.local
vhost (D:\xampp\apache\conf\extra\httpd-vhosts.conf) file
<VirtualHost *:80>
DocumentRoot "D:\xampp\htdocs\sample"
ServerName sample.local
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/anothersample"
ServerName anothersample.local
</VirtualHost>
And by default in windows virtual host is uncommented
After restarting apache and mysql.The Virtual host is running now.I hope this may help someone in the future.
E:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/dev2017/schools"
ServerName dev.schools
<Directory "E:/xampp/htdocs/dev2017/schools">
</Directory>
</VirtualHost>
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 dev.schools
NOTE: Restart Xampp Server.
Type URL: http://dev.schools
Maybe my issue is different.
Above answer not worked for me Windows 10, XAMPP portable 5.6.30
My XAMPP works on port 80 but when I set virtual host then its localhost also go to virtual host folder. So http://localhost also shows the content of http://mydrupal
I simply added this to /apache/conf/extra/httpd-vhosts.conf file as well.
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs"
ServerName localhost
<Directory D:/xampp/htdocs>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Above code was not required on Windows 7.
For virtual host - mydrupal
<VirtualHost *:80>
DocumentRoot "D:/vhosts/drupal"
ServerName mydrupal
<Directory D:/vhosts>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Hope this helps.

Only apply virtual host when the server name is used as host

So I have a project in folder htdocs/project. I need to access this project via domain project.xx to test subdomain mod_rewrite. To do this, I modified my hosts file to map the project.xx to 127.0.0.1.
Then, I have created a virtual host in apache using this code:
<VirtualHost *:80>
ServerName project.xx
ServerAlias www.project.xx
DocumentRoot C:/xampp/htdocs/project/
</VirtualHost>
It works as expected and when navigating to http://project.xx I end up on site running in C:/xampp/htdocs/project/.
I was just editing something else and I have discovered that something is wrong - navigating to 127.0.0.1 will also take me to my project site.
How do I prevent the virtual host setting from affecting whole localhost? I only want to go to my project when browser sends project.xx as the Host header.
As I learned on #httpd IRC chanell, it's required that you also set virtual host for the localhost itself, once you started using localhost.
This means that before matching the domain project.xx, a rule for 127.0.0.1 and localhost muse exist - so that if the domain isn't specified, default behavior will be used:
#Rule for localhost as it normaly behaves
<VirtualHost *:80>
#IP and `localhost` domain name
ServerName 127.0.0.1
ServerAlias localhost
#The normal document root
DocumentRoot C:/xampp/htdocs/
</VirtualHost>
#Rule for your project
<VirtualHost *:80>
ServerName project.xx
ServerAlias www.project.xx
DocumentRoot C:/xampp/htdocs/project/
</VirtualHost>

Multiple Virtual Hosts on Different Ports in WAMP

So I have this problem...
I use WAMP and have set up perfectly working Virtual Hosts in the past, but now I have come to something I never foresaw.
I am trying to do this:
Access C:\wamp\www through http://localhost
Access D:\somethingelse through http://localhost:8080 OR http://something.dev
I much prefer using the proper http://something.dev, as the working site is http://something.co, and so I can keep them separate.
I have followed guides and read forum posts, but all I have manages to do so far is this:
Access C:\wamp\www through http://localhost OR http://something.dev
Access D:\somethingelse through http://localhost:8080 OR http://something.dev:8080
Anybody got any idea how you would do this? Here's my VirtualHost Code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:\wamp\www"
ServerName localhost
ServerAlias www.localhost.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster#something
DocumentRoot "D:/something/www"
ServerName something.dev
ServerAlias www.something.dev
ErrorLog "logs/something-error.log"
CustomLog "logs/something-access.log" common
<directory "D:/something/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</directory>
</VirtualHost>
And in httpd.conf I have this
Listen *:80
Listen *:8080
And my hosts file is working and points both of these to 127.0.0.1
(The reason I want to do this is that when I code on my machine I use the http://something.dev, but I run Livereload Windows, and test my website simultaneously on an iPhone and iPad on the same local network, but without any access to iOS's equivalent of the hosts file. It also allows me to open up only a specific part of my server to the internet, through port forwarding on my router.)
I suppose you have solved the issue. Anyway is good to share some nice information on how to set up multiple Virtual Hosts in Wamp. This is working for me:
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
In my case I am working with ports 8080 and 8181. 8080 is redirecting to a subfolder under c:\wamp\www\myfolder, while 8181 is redirecting to root c:\wamp\www.
To make 8181 work I had to edit httpd-vhosts.conf, hosts (in \drivers\etc folder) and httpd.conf.
In httpd.conf my Apache is listening:
Listen 8080
Listen 8181
also I uncommented:
Include conf/extra/httpd-vhosts.conf
my root is pointing to
DocumentRoot "c:/wamp/www/myfolder"
root directory is configured as:
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
and added:
<VirtualHost *:8181>
DocumentRoot "C:\wamp\www"
ServerName name-of-my-fake-server
</VirtualHost>
in httpd-vhosts.conf I have set:
NameVirtualHost *:8181
in hosts (c:\windows\system32\drivers\etc) I have added:
127.0.0.1 localhost
127.0.0.1 name-of-my-fake-server #My Test Site
Doing that I have now two ports working 8080 and 8181: so 8080 points to directory "c:\wamp\www\myfolder" and the other port 8181 points to my root folder "c:\wamp\www\"
Using * as the hostname requires the use of NameVirtualHost:
NameVirtualHost *:80
NameVirtualHost *:8080
For those with MAMP, edit the httpd.conf
nano /Applications/MAMP/conf/apache/httpd.conf
Add Listen for each port
Listen 80
Listen 8080
And the ServerName too
ServerName localhost:80
ServerName localhost:8080
Once done that, edit httpd-vhosts.conf
nano /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Define NameVirtualHost
NameVirtualHost *:80
NameVirtualHost *:8080
And the VirtualHost's
<VirtualHost *:80>
DocumentRoot "/Users/yourUser/path/project1"
ServerName project1.local
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Users/yourUser/path/project2"
ServerName project2.local
</VirtualHost>
Of course you need to have project1.local and project2.local in your hosts file
sudo nano /etc/hosts
And add
127.0.0.1 project1.local project2.local
Restart MAMP and you could access your vhost by
project1.local
project2.local:8080
project2 could be access also in your network or with a external IP (e.g to test from a different device like a mobile phone). Assuming your IP is 192.168.1.10
192.168.1.10:8080
The question is a little about it. But I assumed that it's near there and may be helpful for somebody.
Recently I met the problem when I need to get access to a few resources (debian repository, my website and phpmyadmin) by one external IP address and port.
After learning the problem I found technology named as reverse proxy. It like proxy but server is accepting all connection from many users and redirect to one target (your server).
I made simple Docker image and docker-compose file and push that to github.com/urpylka/docker-nginx-reverse-proxy and hub.docker.com.
Config file is very simple:
server {
listen 80;
server_name smirart.ru robotic.lol;
location / {
proxy_pass http://robotic.lol:1080/;
}
}
server {
listen 80;
server_name repo.smirart.ru;
location / {
proxy_pass http://8.8.8.8:2080/;
}
}
You can use that for few web-servers running by different IP.

Accessing localhost Webserver Over Network

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.