Hello,
I have set up a website on my Ubuntu desktop using Apache, but i can't access it from another machine via IP address. Which configurations should I add to access it via IP eg: instead of localhost.
Thanks.
Hello,
I have set up a website on my Ubuntu desktop using Apache, but i can't access it from another machine via IP address. Which configurations should I add to access it via IP eg: instead of localhost.
Thanks.
Short summary and checklist (complements what and mentioned about vhosts): most failures to reach an Apache site by IP are networking or binding problems rather than a missing HTML file. The three things to confirm are (1) the server actually has the IP the remote machine is using, (2) Apache is listening on that IP (not only on localhost/loopback), and (3) nothing (local firewall, router/VM NAT) is blocking port 80.
Quick, safe checks and useful commands:
Verify server IP and interfaces:
hostname -I
ip addr show Confirm Apache is running and listening on TCP/80, and list vhost mapping:
sudo systemctl status apache2 # or: sudo service apache2 status
sudo ss -ltnp | grep :80
sudo apache2ctl -S Test reachability from the other machine:
ping <server-ip>
curl -I http://<server-ip>/
# to target a name-based vhost by Host header:
curl -H "Host: example.local" http://<server-ip>/ Check firewall/NAT (Ubuntu desktop often has ufw; VMs/routers can NAT):
sudo ufw status verbose
sudo ufw allow 80/tcp
sudo iptables -L -n Ubuntu-specific notes: enabled-site files live in /etc/apache2/sites-available and /etc/apache2/sites-enabled; use sudo a2ensite <conf> and reload Apache (sudo systemctl reload apache2 or sudo service apache2 reload) after changes. If Apache is listening but the wrong site appears when connecting by IP, that is expected with name-based vhosts — apache2ctl -S shows which vhost is default. Directory access rules differ by Apache version (2.4 uses Require all granted), so confirm the DocumentRoot directory allows external access.
Extra checks: if Apache is inside a VM, switch the VM NIC to bridged mode (not NAT) for LAN access; on desktops, disable any host-only adapters that might shadow the intended interface. Security caution: opening 80 to wider networks exposes the server — confirm intent before enabling public access.
Jump to Post— rch1231 169you have to tell apache what the default web site is for the server put something like this in the httpd.conf file:
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /www/docs/dummy-host.example.com ServerName dummy-host.example.com ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost>
you have to tell apache what the default web site is for the server put something like this in the httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost> If your both machines are communicating with each other then other machine can access your server with IP based on the VHOST configuration you have setup (default VHOST will be called by default).
Thanks,
Manoj Samtani
Correct, the virtual host either has to be the first (default) entry for the named based Vhost, are it needs to be setup as an IP based vhost.
:) For more info please refer this link
---
Manoj Samtani
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.