Apache Virtual Host (Subdomain) access with different computer on LAN

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 16:53:00

Ok, I figured it out, here are the configuration if anyone else is looking for this:

==================================================================================

Machine A (Apache HTTP Server): httpd-vhost:

NameVirtualHost *:50080

<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias alias <!-- Added -->
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin administrator@development.localhost
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost
    ServerAlias development.phoenix <!-- Added -->
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

hosts:

127.0.0.1 development.localhost

127.0.0.1 alias
127.0.0.1 development.alias

==================================================================================

Machine B (Guest Machine): hosts:

10.0.0.10 alias
10.0.0.10 development.alias

From the second machine, you should be able to access with "alias" and "development.alias"

I suggest making the following change (add the ServerAlias lines):

NameVirtualHost *:50080
<VirtualHost *:50080>
    DocumentRoot "C:/www/HTTP"
    ServerName localhost
    ServerAlias cms.myserver.com
</VirtualHost>

<VirtualHost *:50080>
    ServerAdmin administrator@development.localhost
    DocumentRoot "C:/www/HTTP/development"
    ServerName development.localhost 
    ServerAlias development.myserver.com
    ErrorLog "logs/development.localhost-error.log"
    CustomLog "logs/development.localhost-access.log" common
</VirtualHost>

Restart Apache to ensure the changes take effect.

Then on your second computer you need to add a custom dns entry for these new domain names. If it is Windows, edit the file c:\windows\system32\drivers\etc\hosts. If it is Linux, edit /etc/hosts. Either way add:

10.0.0.10 development.myserver.com
10.0.0.10 cms.myserver.com

Now on your second computer you should be able to access the following URLs:

http://development.myserver.com:50080
http://cms.myserver.com:50080

Unless I'm missing something, you'll need to either set up DNS entries, or add entries to the /etc/hosts file of each computer accessing the server.

localhost is an entry that exists in everyone's /etc/hosts file by default, always pointing to 127.0.0.1. Without adding a /etc/hosts entry, developer.localhost doesn't exist, and prefixing an ip address with a subdomain won't work at all.

Using a SSH + Putty tunnel, and thus having a 127.0.0.1 on my server, I managed to access my subdomains by doing the following on my server side:

# nano /etc/hosts

127.0.0.1  localhost.localdomain localhost
127.0.0.1  sub1.domain.com sub2.domain.com sub3.domain.com sub4.domain.com

I did not change the host file of the remote computer, and it works like a charm

For Named Virtual Hosts you need to use a hostname or domainname to connect to you apache server. It does not work with ips.

You could insert an entry in your /etc/hosts on your second system.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!