View Apache Virtual Host Without Domain (HTTP & HTTPS)
In this article
This guide shows how to access an Apache virtual host using its IP address or localhost, without needing a registered domain name, for both HTTP and HTTPS. You'll learn how to configure Apache to respond correctly and how to bypass certificate warnings for self-signed certificates. This is useful for testing websites locally or on a private network before going live.
What You'll Need
- Apache web server installed and running (version 2.4.x recommended).
- Access to the server's configuration files (usually in
/etc/apache2/on Debian/Ubuntu, or/etc/httpd/on RHEL/CentOS). - Root or sudo privileges to edit those files.
- For HTTPS: OpenSSL installed to generate a self-signed certificate.
- A web browser to test the result.
Step-by-Step
- Identify your server's IP address – Run
ip addrorhostname -Ion Linux. If you're testing on the same machine, you can use127.0.0.1orlocalhost. - Create a directory for your site – For example,
sudo mkdir -p /var/www/mysiteand add a simpleindex.htmlfile inside it with some test content. - Create a virtual host configuration file – Navigate to your Apache sites-available directory (e.g.,
/etc/apache2/sites-available/) and create a file namedmysite.conf. - Configure the HTTP virtual host – Edit the file with a text editor and add the following, replacing the IP and paths with your own:
<VirtualHost *:80> ServerName 192.168.1.100 DocumentRoot /var/www/mysite <Directory /var/www/mysite> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>Note: Using*:80means it responds on any IP, but theServerNamecan be your IP orlocalhost. If you have multiple virtual hosts, you may need to setServerNameto the exact IP you're using. - Enable the site and reload Apache – Run
sudo a2ensite mysite.conf(Debian/Ubuntu) or create a symlink in/etc/httpd/conf.d/(RHEL). Then reload withsudo systemctl reload apache2(orhttpd). - Test HTTP access – Open a browser and go to
http://192.168.1.100(orhttp://localhost). You should see your test page. - Generate a self-signed SSL certificate – For HTTPS, create a certificate and key with:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ -keyout /etc/ssl/private/mysite.key \ -out /etc/ssl/certs/mysite.crtAnswer the prompts; the common name can be your IP or localhost. - Configure the HTTPS virtual host – Add another block to the same file (or a new file) for port 443:
<VirtualHost *:443> ServerName 192.168.1.100 DocumentRoot /var/www/mysite SSLEngine on SSLCertificateFile /etc/ssl/certs/mysite.crt SSLCertificateKeyFile /etc/ssl/private/mysite.key <Directory /var/www/mysite> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>Make sure the SSL module is enabled:sudo a2enmod ssl(Debian/Ubuntu) or ensuremod_sslis loaded. - Reload Apache again – Use the same reload command as before.
- Test HTTPS access – Visit
https://192.168.1.100. Your browser will warn about the self-signed certificate; click through to accept the risk and proceed.
Common Mistakes
- Using a domain name in ServerName – If you use
example.combut don't have DNS pointing to your server, the virtual host won't match. Use the IP or localhost. - Forgetting to enable the site – On Debian/Ubuntu, if you don't run
a2ensite, the config is ignored. - Port 443 not open – If a firewall is active, HTTPS requests may be blocked. Allow port 443 (and 80) in your firewall settings.
- Certificate file permissions – Apache must be able to read the key and cert files. Ensure they are owned by root and have appropriate permissions (e.g., 600 for the key).
- Not reloading Apache – Changes to config files require a reload or restart to take effect.
Tips
- Use
127.0.0.1instead oflocalhostto avoid IPv6 issues (::1) that may cause mismatches. - If you have multiple sites, set distinct port numbers (e.g., 8080, 8443) to differentiate them without domain names.
- For easier testing, add an entry to your local
hostsfile mapping a fake domain to your IP (e.g.,192.168.1.100 mytest.local), but this guide focuses on IP-only access. - Use
curl -k https://192.168.1.100from the command line to test HTTPS without certificate verification. - Keep your self-signed certificate for development only; never use it in production.
Troubleshooting
- Site not loading at all – Check Apache error logs:
sudo tail -f /var/log/apache2/error.log(or/var/log/httpd/error_log). Look for syntax errors or missing modules. - Default page appears instead of your site – This usually means your virtual host isn't being used. Verify that
ServerNamematches the IP you're accessing, and that your config file is enabled. - HTTPS shows “This site can’t be reached” – Check if the SSL module is loaded (
apache2ctl -M | grep ssl). Also confirm that port 443 is listening (sudo netstat -tulpn | grep :443). - Certificate error persists even after clicking through – In some browsers, you may need to type
thisisunsafeon the warning page (Chrome) or add an exception manually. This is normal for self-signed certs. - 403 Forbidden – This indicates a directory permissions issue. Ensure the DocumentRoot and its contents are readable by the Apache user (usually
www-data). Set permissions likesudo chown -R www-data:www-data /var/www/mysite. - Virtual host on a different port not working – If you use a non-standard port, make sure you add
Listen 8080to your main config and specify that port in the<VirtualHost>tag.
Frequently Asked Questions
Can I use a domain name that I don't own?
Yes, for local testing you can edit your hosts file to point any domain to 127.0.0.1, but this guide focuses on IP-based access for simplicity.
Why do I get a “ServerName” warning when reloading Apache?
Apache warns if no global ServerName is set. You can ignore it if your virtual hosts have their own ServerName, or set one in the main config (e.g., ServerName 127.0.0.1).
Is it safe to use a self-signed certificate?
It's safe for testing and development because traffic is encrypted, but browsers will warn users. Never use it for a public-facing site.
How do I make my site accessible from other devices on the network?
Use your server's LAN IP (e.g., 192.168.1.100) and ensure the firewall allows connections on ports 80/443. Other devices can then access it via that IP.
What if I have multiple virtual hosts without domains?
You can assign each a different port (e.g., 8080, 8081) and access them via http://IP:8080 etc. Or use different IPs if your server has multiple network interfaces.
Can I use a wildcard certificate for multiple subdomains?
Yes, but that requires a valid domain and a CA-issued certificate. For local IPs, self-signed certificates are the only practical option.