Score:1

Subdomain redirection (proxy) not working (tried with Apache2 and Nginx)

mv flag

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.

Score:0
mv flag

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.

Score:0
us flag

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.

tholeb avatar
mv flag
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 ?
us flag
Use a public domain and get name servers for it, where you install the domain names.
tholeb avatar
mv flag
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)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.