✓ Solved

Setup reverse proxy for subdomain

Hi everyone,

I hope someone can help me with this. I have a Linode running apache on Ubuntu 22.04 which is pointing to mydomain.net. There is a basic html page in place for this which is working with SSL. There also 2 subdomains, sd1.mydomain.net and sd2.mydomain.net. All three have A records in the DNS and resolve to mydomain.net.

I want sd1.mydomain.net and sd2.mydomain.net to both point to their own pages. These will in future host NextCloud and SimpleLogin, but for now I'm learning and just trying to figure out how to set this up correctly.

Proxy.conf, proxy_http.load and proxy.load are installed.

I know I need to edit one of the .conf files, but I'm not sure which one. Do I need to update the root mydomain.net.conf or sd1 / sd2.mydomain.conf?

This is my current .conf file for the root domain. (I've had to wrap the < in double quotes due to mark down, they're not there in the .conf e.g. <Virtual… not "<"…)

"<"VirtualHost *:80>
ServerAdmin webmaster@email.com
ServerName mydomain.net
ServerAlias www.mydomain.net
DocumentRoot /var/www/html/mydomain.net/public_html/
ErrorLog /var/www/html/mydomain.net/logs/error.log
CustomLog /var/www/html/mydomain.net/logs/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} = mydomain.net [OR]
RewriteCond %{SERVER_NAME} = www.mydomain.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,Replacement]
"<"/VirtualHost>

I'm not sure how to redirect the subdomains and if I need to manually set the ports for this.

Hope this makes sense.

Any help is much appreciated.

6 Replies

✓ Best Answer

the sd1.mydomain.net address still takes me to the mydomain.net site.

Did you blow your browser cache first? On iOS it’s in the browser settings called Clear History & Website Data. Your browser has something similar…

do I need to any port forwarding?

No. apache will route the results to the correct virtual host based on the requested URL.

— sw

Set up 3 <VirtualHost>s -- one for each of mydomain.net, sd1.mydomain.net and sd2.mydomain.net (and don't use mod_rewrite):

<VirtualHost *:80>
ServerAdmin webmaster@email.com
ServerName mydomain.net
ServerAlias www.mydomain.net
DocumentRoot /var/www/html/mydomain.net/public_html/
ErrorLog /var/www/html/mydomain.net/logs/error.log
CustomLog /var/www/html/mydomain.net/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@email.com
ServerName sd1.mydomain.net
ServerAlias www.sd1.mydomain.net  # leave this out if you don't want it
DocumentRoot /var/www/html/sd1.mydomain.net/public_html/
ErrorLog /var/www/html/sd1.mydomain.net/logs/error.log
CustomLog /var/www/html/sd1.mydomain.net/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
ServerAdmin webmaster@email.com
ServerName sd2.mydomain.net
ServerAlias www.sd2.mydomain.net  # leave this out if you don't want it
DocumentRoot /var/www/html/sd2.mydomain.net/public_html/
ErrorLog /var/www/html/sd2.mydomain.net/logs/error.log
CustomLog /var/www/html/sd2.mydomain.net/logs/access.log combined
</VirtualHost>

-- sw

Thanks for this Stevewi,

I've made the amendments as recommended above (removed the mod_write as well) by placing all of the above into one file mydomain.net.conf.

I've moved the old .conf files for the subdomains for now and restarted apache, but the sd1.mydomain.net address still takes me to the mydomain.net site. There is a separate index.html file in the document root folder for SD1.

I'm new to apache so still getting my head around this, do I need to any port forwarding? I've figured out how to open ports (thinking of 2000 & 2100 as these are free) and use the listen option?

Many thanks for that, nice and simple and it worked a charm!

For some reason my browser won't refresh or update even after I've cleared the cache and cookies etc, but trying another browser shows the updates and they're all SSL secure.

Cheers :)

So, the last thing you should do is split the 3 different virtual hosts into 3 different .conf files in /etc/apache2/sites-available so you can enable/disable them independently with a2ensite/a2dissite.

— sw

Ah, hadn't thought of that! I've been on a bit of a learning curve this week looking at this.

I've already got my NextCloud instance up and running in one and a couple of place holder pages for other sites, but they're all in the mydomain.net.conf file and this is the only site that's enabled…

Should I have created them all separately?

DG

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct