0

I've set up three virtual hosts in apache 2.4 with the following entrys:

<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName www.xx.de
</VirtualHost>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/sh/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName sh.xx.de
</VirtualHost>
<VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/nc/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ServerName n.xx.de
</VirtualHost>

The access works from the internet as well as from local network. But if I'm in local network, I want to redirect querys to the local IP not to the external IP. The DNS is on the same device as the apache is. I've already tried using dnsmasq to resolve xx.de with the local IP 192.168.0.55. This works, if I'm using xx.de/sh/ for example. But sh.xx.de doesn't work.

  • Have you added a DNS entry for sh.xx.de in your local dnsmasq.conf file? If not, the local resolver won't know it's supposed to deliver that internal IP address. – roaima Apr 15 at 14:04
  • I added: host-record=sh.xx.de,192.168.0.55 in a custom dnsmasq.conf. But that doesn't work, it's redirecting to 192.168.0.55 and not to 192.168.0.55/sh – Ammy Apr 17 at 11:48
  • Using the dnsmasq.conf record you've described along with the Apache configuration in your question, I would expect http://sh.xx.de/ to deliver content from /var/www/html/sh/. If this is not happening you need to edit your question to explain in more detail what you want, and what happens instead. Please do not use the phrase "it's not working" because that doesn't tell us either what you want or what you actually see. – roaima Apr 17 at 13:08
0

DNS only maps IP addresses to Hostnames and vice versa, not to a URL

A URL is made up of 3* parts, lets take http://example.com/foo:

  1. a Scheme e.g. http:
  2. a Host e.g. example.com
  3. a Path e.g. /foo

So when the browser on your computer requests http://example.com/foo the DNS will convert example.com to the IP address. The computer will then use the IP address to connect to the remote machine on the default Scheme port (80 for http).

Once connected it will make a HTTP request (e.g GET /foo) and as part of the request it will include the HTTP Host Header. This header tells the HTTP server which hostname the browser looked up in the DNS. This then allows the HTTP server to map the request to the correct Virtual Host.

It sounds like you need to set up 3 virtual hosts on the machine with the IP address 192.168.0.55.

  1. one for a.xx.com
  2. one for b.xx.com
  3. a default virtual host (to cover the raw IP address 192.168.0.55) that hosts the actual /aaaa and /bbbb directories

The first 2 should redirect to the correct path hosted by the 3rd.

*There can be more parts (e.g. user/password, port and query), but this is enough for this example

  • Thank You! But I've already set up the three virtual hosts. It is already working from the internal network and also from external. But the traffic is always over the internet. I wanted to prevent this by using the dns. So I've got two use cases: 1: I'm outside of my network: a.xx.com leads to xx.com/aaaa, whereby xx.com is resolved with the external ip address --> already working 2: I'm connected with my network: a.xx.com leads to 192.168.0.55/aaaa --> not working yet. The main problem is the usage of the subdomain. "xx.com/aaaa" works currently with the dnsmasq entry, but not "a.xx.com" – Ammy Apr 10 at 12:12
  • That is very different to what the question asks. Please edit the question to match this description. And include the details of how you have configured Apache as that is the important part, not the DNS setup – hardillb Apr 10 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.