1

I'm using a raspberry pi with apache2 to manage my websites. I have multiple docker images running on different ports. I want to redirect (without url changes) scanner.raspberry.local to localhost:1234. To do so, I've followed these two posts :

In the end, I only have one virtualhost working (the first one). Here is my config :

# Home page : working properly
<VirtualHost *:80>
        ServerName          raspberry.local

        ProxyPreserveHost   On
        ProxyRequests       Off

        ProxyPass           / http://localhost:8080/
        ProxyPassReverse    / http://localhost:8080/

        ErrorLog ${APACHE_LOG_DIR}/error-homer.log
        CustomLog ${APACHE_LOG_DIR}/access-homer.log combined
</VirtualHost>

# Scanner : not working : "could not resolve host" when I cURL
<VirtualHost *:80>
        ServerName          scan.raspberry.local

        ProxyPreserveHost   On
        ProxyRequests       Off

        ProxyPass           / http://localhost:1234/
        ProxyPassReverse    / http://localhost:1234/

        ErrorLog ${APACHE_LOG_DIR}/error-scan.log
        CustomLog ${APACHE_LOG_DIR}/access-scan.log combined
</VirtualHost>

I tried installing nginx, but I end up with the same thing, the first virtualhost works, but the second one (the subdomain), couldn't be resolved via cURL, even directly on the server. I've followed this post to help me. I ended with this :

server {
    listen 80;
    server_name raspberry.local;

    location / {
        proxy_pass http://localhost:8080;
    }   
}

server {
    listen 80;
    server_name scan.raspberry.local;

    location / {
        proxy_pass http://localhost:1234;
    }   
}

I have no errors on any log files, when I use apache2ctl -S it finds my virtualhosts with no problems, same when I do apache2ctl configtest. I have enabled the proxy, proxy_http and rewrite modules. And my config is properly enabled in /etc/apache2/sites-enabled/000-default.conf (symlink from sites-available).

My system:

  • Raspberry Pi 4 8Gb on Ubuntu 22.04

Also, I'm using a VPN hosted on my Pi, And i've added the proper config to my /etc/host and c:\Windows\System32\Drivers\etc\hosts (WSL/Windows).

I know there is a ton of posts about apache2's config. But I can't find any with the same problem.

tholeb
  • 31
  • 1
  • 6

2 Answers2

0

Scanner : not working : "could not resolve host" when I cURL

This means that curl cannot resolve the IP address for the domain name. It means that the DNS entry for the destination domain is not configured.

The DNS configuration is not related to Apache2 nor nginx configuration.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Thank you for you answer. I have installed `dnsmasq` and added the local DNS server to `/etc/resolv.conf` and I can curl to the subdomains, that's indeed a problem with the DNS. Is there anyway I can curl the subdomains without modifying the DNS server of each machine ? – tholeb Feb 18 '23 at 11:05
  • Use a public domain and get name servers for it, where you install the domain names. – Tero Kilkanen Feb 18 '23 at 16:47
  • So I should set `*.rasp.example.com` to my IP ? Won't it let anyone access the websites I have on my Raspberry ? Edit : I have to open my ports to work, which is not something I want. I need to have the websites available on local network only (i'll use a VPN if I want to access it somewhere else) – tholeb Feb 19 '23 at 17:17
0

To resolve this, I installed dnsmasq, configured it, and added the DNS server to /etc/resolve.conf.

Now, I can cURL to x.subdomain.local if I add on each machine my DNS server.

tholeb
  • 31
  • 1
  • 6