Score:0

Apache serve service from local host on subdomain

cl flag

I am trying to use Apache to serve multiple sites at the same time, the structure I want to obtain is composed by a main site at example.com and use the subdomains radarr.example.com and sonarr.example.com to access my Radarr and Sonarr servers.

The main site is hosted on machine1, I set up a virtual host using apache and certbot:

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName example.com
  
  WSGIDaemonProcess sflasksite user=www-data group=www-data threads=5
  WSGIScriptAlias / /var/www/webapp/app.wsgi

  <Directory /var/www/webapp>
    WSGIProcessGroup sflasksite
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Require all granted
  </Directory>

  Alias /static /var/www/webapp/static

  <Directory /var/www/webapp/static/>
    Order deny,allow
    Require all granted
  </Directory>

  ErrorLog /var/www/webapp/logs/error.log
  CustomLog /var/www/webapp/logs/access.log combined


SSLCertificateFile /etc/letsencrypt/live/example.com-0002/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0002/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

The two servers I want to serve are on machine2, on the same network as machine1, how can I obtain the two services respectively on radarr.example.com and sonarr.example.com?

After some reading, I tried to use a Reverse Proxy, configuring a virtual host for each service as follows:

<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyRequests Off
  
  ServerAlias radarr.example.com

  ProxyPass / http://192.168.1.20:7878/
  ProxyPassReverse / http://192.168.1.20:7878/

  ErrorLog /var/www/radarr/logs/error.log
  CustomLog /var/www/radarr/logs/access.log combined
</VirtualHost>

and alike for Sonarr.

However, when I navigate to radarr.example.com, I do not get the expected service but the main site.

How can I get the reverse proxy to work? Or should I switch to another strategy altogether?

EDIT: I am also open to abandon apache if someone knows and can suggest a simpler way of doing this.

vidarlo avatar
ar flag
Remember that you have to define vhost for http and https. Or possibly only https even today.
ezra-s avatar
ru flag
check "apachectl -S" for virtualhosts defined. All Virtualhosts must have a ServerName directive, apache checkts Host header, the first virtualhost matching replies the answer, so it must be your "default" virtualhost has a greedy ServerAlias name or similar.
Riccardo Barbieri avatar
cl flag
@DanielFerradal What ServerName should I put in the reverseproxy config? The servername in the "default" virtualhost is example.com (obv not really example but my hostname, just to be clear).
vidarlo avatar
ar flag
You should put what you want to enter in the URL field of the browser to reach that vhost.
Riccardo Barbieri avatar
cl flag
@vidarlo I tried that, I put radarr.example.com in ServerName and commented out ServerAlias and now I simply cannot connect
vidarlo avatar
ar flag
If you can't connect you have a mistake that stops Apache from starting. What's the output of `apachectl configtest`?
Riccardo Barbieri avatar
cl flag
@vidarlo sorry I meant that I can't connect to radarr.example.com, the main site is up and running
vidarlo avatar
ar flag
Then you have a DNS issue. Can you please [edit] your question with the *real* domains?
Riccardo Barbieri avatar
cl flag
@vidarlo I would prefer not to share the real domain, I have defined two CNAME dns entries, named radarr and sonarr on my cloudflare dashboard
ezra-s avatar
ru flag
@RiccardoBarbieri whichever matches the hostname you want to represent but it most not match any further virtualhost servername. For example, use default as www.example.com (AND NOT ServerAlias *.example.com) and your specific virtualhost like somethingelse.example.com. That way when someone requests somethingelse.example.com Apache will know which virtualhost to use. "apachectl -S" should give you enough clues.
Riccardo Barbieri avatar
cl flag
@DanielFerradal I tried to do what you suggested but I still have the same problem, even though I have example.com as ServerName in the main VirtualHost and radarr.example.com in the secondary VirtualHost
Score:0
cl flag

I found out that the problem I was having was due to the fact that I installed ssl certificates only for the domain mydomain.com and not the domain radarr.mydomain.com. I run certbot again for that domain and now it works.

I don't exactly know why it works, if someone has an explanation, please post it and I will add it to the answer.

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.