Accessing local Apache website from remote machine in same network - apache

This is my story.
I installed Apache in windows 7 and configured Virtual host. Below is my directory tree.
D:\
Apache/
PHP/
MySQL/
projects/
and virtual host configuration.
<VirtualHost stuff.dev>
DocumentRoot "D:/projects/stuff"
ServerName stuff.dev
ServerAlias stuff.dev
<Directory "D:/projects/stuff">
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I also add host name in hosts file. I could accessed stuff.dev in local machine but I can't access from remote machine although I add host name in remote's hosts files.
When I access website from remote machine, It's always access to default host (htdocs/index.html).
How can I access local website from remote machine?

If you can access via localhost and not from your other computer, the issue is your Windows Firewall.... try to disable it or configure it to handle port 80
If Windows Firewall is disabled and still not working make sure you don't have any application (like Skype) that is conflicted with Apache port 80

Related

How to access Virtual Hosts setup on the VM from the Host Machine?

I want to access my virtual hosts (websites) that I've set up in my VirtualBox -> Ubuntu-Server 18. I have apache2 installed and everything is setup.
The host machine (macOS) can presently gain access to the default website of apache2 in the guest (Ubuntu-server) through a Port Forwarding rule I have assigned in the VirtualBox Network Settings:
127.0.0.1:8000 -> 10.0.2.15:80
I've set up a virtual host in my guest machine with the following configuration:
<VirtualHost *:80>
ServerName dropn.taxi
ServerAdmin admin#dropn.taxi
DocumentRoot /var/www/dropn.taxi/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The DocumentRoot directory mentioned above exists and has the files necessary to serve a basic "Hello World" home page. I've tested it with my apache installed in my local machine as well. The website's not the problem.
But everytime I access localhost:8000 from the local machine, I'm greeted with an Ubnutu-Apache greetings page. Whereas when I try localhost:8000/dropn.taxi, I get a 404 page. I've researched quite a bit and the closest I can get to a solution is what is suggested in this page:
Ubuntu Apache2 local virtual hosts url not found
Simply put: How can I access virtual hosts of the guest machine (VM) from the host machine?
Still not specific to my case. Would appreciate any help in this regards.
localhost in the apache2 server is set to point to /var/www/html by default. For the virtual hosts to work properly, the domain name accessing them must be what is defined in the ServerName field.
localhost:8000/dropn.taxi would translate to 127.0.0.1/dropn.taxi in the VM guest. Which means, it is trying to access the /var/www/html/dropn.taxi, which, ultimately does not exist, hence the 404 error.
The solution to this is to add dropn.taxi to the /etc/hosts file in both the Host Machine and the VM. The line would look like:
127.0.0.1 localhost dropn.taxi
While accessing from the Host Machine, we use dropn.taxi:8000 in the browser whereas the port :8000 is not used in the guest machine. This way, whenever accessing the virtual hosts, the domain name accessing them matches the ServerName field and it simply works!

Accessing local host from another machine

I have seen many answers on this with what would appear to be simple solutions, none of which are working for me at this time.
I have WAMP install with Apache 2.4.33 32bit installed on a PC. I can access the site on that PC without a problem using the alias mySite.local.
The PC's host file looks like this
127.0.0.1 mySite.local
The remote lap top's host file is
192.168.1.114 mySite.local
That is the IP of the PC on the network.
httpd.conf
Listen 80
ServerName mySite.local:80
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "H:/Intranet/mySite_v2_www/public"
httpd-vhosts.conf
<VirtualHost *:80>
ServerName mySite.local
DocumentRoot "H:/Intranet/mySite_v2_www/public"
</VirtualHost>
I have tried disabling the windows firewall and virus checker on the PC.
The laptop appears to be getting there but being blocked. The message is..
Forbidden
You don't have permission to access / on this server.
Apache/2.4.33 (Win32) PHP/7.2.4 Server at mySite.local Port 80
So it looks like it can see Apache but is being blocked. So what else needs to be set to get access to the server?
Here are two of the links that I have been following to try and get this to work
Error message "Forbidden You don't have permission to access / on this server"
and
How do I connect to this localhost from another computer on the same network?
Thanks for any direction you can provide.
To complement the answer of Paul Neale:
Forbidden You don't have permission to access / on this server. Apache/2.4.33 (Win32) PHP/7.2.4 Server at mySite.local Port 80
That message is an answer from Apache. Disabling the windows firewall and virus checker on the PC won't have any effect, you are already reaching Apache there is not any networking problem.
Apache is receiving your request to access the root folder "public":
H:/Intranet/mySite_v2_www/public
But denies the request because, the directive Require local is enabled. This directive means, you can access to the content of public from the local server (localhost), which is the same to say 127.0.0.0 or localhost.
What you wanted is to tell apache that allows the access of certain IP address to the root directory "public".
When you changed the directive to Require all granted you are telling apache that, no matter who asks, give it access to / (root folder) in other words "public".
So, what you was searching for is "Access Control" in apache, and the directive Require can be used with IP address, here's the main document from Apache, this is an example:
Require host address
Require ip ip.address
It's important to differentiate between Network//Permissions problems. If you want to know if you are able to communicate (At network level) with Apache, you could do:
telnet <IP_APACHE_SERVER> <PORT_APACHE_SERVER>
#example: telnet 172.10.10.2 80
So after playing around will combinations for a day I found that in the httpd.conf I needed to change Require local to Require all granted in the section.
<Directory "H:/Intranet/mySite_v2_www/public/">
Options +Indexes +FollowSymLinks +Multiviews
AllowOverride all
# onlineoffline tag - don't remove
# Require local
Require all granted
</Directory>

Apache connection refused outside of localhost

I'm running Ubuntu on vmware under windows 10, I set up and configured my apache to these configurations:
/etc/apache2/apache2.conf
<Directory /> ... stuff ... Require all granted </Directory>
VirtualHost1
<Directory ...>
....
AllowOverride All
Require all granted
</>
When I call the website from within the ubuntu on my vm it's reached fine, but when I call this site from my windows vm host machine my conn. gets refused.
This is my ubuntu hosts file:
127.0.0.1 test.com www.test.com
this is my windows hosts file
127.0.0.1 test.com www.test.com
**** All the listings here are approximate, so don't quote mistakes in code, apache restarts just fine
For all intent and purposes, a virtual machine is not the same as the host machine. Their network is totally separate.
If your virtual network is bridged, you need to access your ubuntu web server from it's public interface, usually eth0. This means, you will need to edit hosts file in windows to point www.test.com to the public ip address of ubuntu.
If your virtual network is NATted, you need to configure port-forwarding. I recommend using the same port numbers, if possible, for ease of use. You can keep the windows host table the same way you already have.
In both cases, the apache web server should listen on the public interface.
This depends on how you have configured you virtual host networking settings.
The 127.0.0.1 refers to you windows host on the windows machine and 127.0.0.1 refers to the ubuntu host on the virtual machine. The concept localhost (127.0.0.1) is always local host and should not leave the actual network interface (virtual or not). You need to contact you virtual host on virtually "external" ip-number from windows.
You can get the ubuntu ip-number by running "ifconfig" in a shell.
Best regards
Jørgen

Using IIS and Apache on same server

I have a server running both Apache and IIS. IIS is using port 80 and every domain name hosted on the server using iis works fine. Now i also have apache running and is listen on port 8080. Is is possible that i have a domain www.example.com and it uses Apache, but i do not have to type www.example.com:8080 to get the site , but i go on www.example.com to get the site. I can host php on iis and all that but i want to use Apache for that website. I am currently this on httpd.conf
<VirtualHost *>
DocumentRoot "${path}/data/localweb/example"
ServerName www.example.com
<Directory "${path}/data/localweb/example">
Options FollowSymLinks Indexes
AllowOverride All
Order allow,deny
Allow from all
#Deny from all
Require all granted
</Directory>
# Other directives here
</VirtualHost>
If you have the ability to use multiple IP address oh the web server you could bind the IIS site to one on port 80 and the Apache site to port 80 on the second. If it's a VM you can just add another virtual network interface, if it's a physical server you can add a new network card.
If you only have one IP address you could setup ARR+ URL rewrite to use the IIS server to act as a reverse proxy to the apache site.

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