jontek2
Posts: 7
Joined: Thu Jul 13, 2017 1:46 pm

Second raspberry pi for subdomain

Thu Jul 13, 2017 9:37 pm

Hey,

I currently have two raspberry pi running a webserver. Raspberry 1 is using apache and hosting my files, Raspberry 2 is hosting the database. My domain.com is pointed with Dynamic DNS (thru namecheap) to my external ip and port forwarding.

Now i want to add another Raspberry Pi for a staging environment. How can i point my subdomain (i.e sub.domain.com) to my new raspberry pi?

Thanks

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 9:58 am

jontek2 wrote:Hey,

I currently have two raspberry pi running a webserver. Raspberry 1 is using apache and hosting my files, Raspberry 2 is hosting the database. My domain.com is pointed with Dynamic DNS (thru namecheap) to my external ip and port forwarding.

Now i want to add another Raspberry Pi for a staging environment. How can i point my subdomain (i.e sub.domain.com) to my new raspberry pi?
Assuming you've only got a single external IP (as the majority of people will have) you could either use a different port on your router and forward that to the new Pi. The other option would be to have the original Pi act as a proxy for sub.domain and forward the requests to the staging environment.

jontek2
Posts: 7
Joined: Thu Jul 13, 2017 1:46 pm

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 10:35 am

mfa298 wrote:
jontek2 wrote:Hey,

I currently have two raspberry pi running a webserver. Raspberry 1 is using apache and hosting my files, Raspberry 2 is hosting the database. My domain.com is pointed with Dynamic DNS (thru namecheap) to my external ip and port forwarding.

Now i want to add another Raspberry Pi for a staging environment. How can i point my subdomain (i.e sub.domain.com) to my new raspberry pi?
Assuming you've only got a single external IP (as the majority of people will have) you could either use a different port on your router and forward that to the new Pi. The other option would be to have the original Pi act as a proxy for sub.domain and forward the requests to the staging environment.
I've got a single external IP.

I guess i could do the port forwarding to my new RBPI and on the RBPI update what port it listens to. However, i do not see any support for ports on namecheap with Dynamic DNS for my domain. Do i just add my subdomain and my external IP and update the /etc/ddclient.conf on my new RBPI for my subdomain?

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 12:19 pm

jontek2 wrote: I've got a single external IP.

I guess i could do the port forwarding to my new RBPI and on the RBPI update what port it listens to. However, i do not see any support for ports on namecheap with Dynamic DNS for my domain. Do i just add my subdomain and my external IP and update the /etc/ddclient.conf on my new RBPI for my subdomain?
If you got that route you'de have the same IP set for but domain and sub.domain, then you go to the staging server you would need to specify the port to use (http://sub.domain:8080) you would also find that domain:8080 would take you to the staging server and http://sub.domain would to to the main server (but you could get apache to provide redirects to the right name in those cases)

DNS is only a name -> IP mapping, you cant provide ports (that's why common services have default ports they run on)

S0litaire
Posts: 216
Joined: Thu Dec 29, 2011 4:24 pm
Location: Ayrshire, Scotland
Contact: ICQ Skype Twitter

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 12:20 pm

take a look at this :

https://serverfault.com/questions/41578 ... t-local-ip

It might be possible without messing about with port numbers, and just use apache/Niginx itself to redirect the sub-domain to another internal IP address
--
Laters

Bill "Solitaire" C

Anáil nathrach, ortha bhas betha, do cheol déanta

User avatar
rpdom
Posts: 15588
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 8:07 pm

Using your web server as a reverse proxy is the way to go. Just set the virtual host to forward requests to the other Pi.

jontek2
Posts: 7
Joined: Thu Jul 13, 2017 1:46 pm

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 9:47 pm

S0litaire wrote:take a look at this :

https://serverfault.com/questions/41578 ... t-local-ip

It might be possible without messing about with port numbers, and just use apache/Niginx itself to redirect the sub-domain to another internal IP address
I've tried this but don't get it working. I've have done the following (where domain.com is the exampel URL):

FYI webserver is at 10.0.1.24 and new staging server is on 10.0.1.6

1. cd /etc/apache2/sites-available
2. sudo nano dev.domain.com.conf
3. Pasted in the following:

Code: Select all

<VirtualHost *:80>    
        ServerName dev.domain.com
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://10.0.1.6/
                ProxyPassReverse http://10.0.1.6/
        </Location>    
</VirtualHost>
4. sudo a2ensite dev.domain.com.conf
5. sudo systemctl restart apache2

What's happining now is that dev.domain.com gives connection refused and my current domain.com and http://www.domain.com also stops working.

Help :-)

S0litaire
Posts: 216
Joined: Thu Dec 29, 2011 4:24 pm
Location: Ayrshire, Scotland
Contact: ICQ Skype Twitter

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 9:54 pm

jontek2 wrote:
S0litaire wrote:take a look at this :

https://serverfault.com/questions/41578 ... t-local-ip

It might be possible without messing about with port numbers, and just use apache/Niginx itself to redirect the sub-domain to another internal IP address
I've tried this but don't get it working. I've have done the following (where domain.com is the exampel URL):

FYI webserver is at 10.0.1.24 and new staging server is on 10.0.1.6

1. cd /etc/apache2/sites-available
2. sudo nano dev.domain.com.conf
3. Pasted in the following:

Code: Select all

<VirtualHost *:80>    
        ServerName dev.domain.com
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://10.0.1.6/
                ProxyPassReverse http://10.0.1.6/
        </Location>    
</VirtualHost>
4. sudo a2ensite dev.domain.com.conf
5. sudo systemctl restart apache2

What's happining now is that dev.domain.com gives connection refused and my current domain.com and http://www.domain.com also stops working.

Help :-)
Have got installed the proxypass module for Apache??

https://www.digitalocean.com/community/ ... -extension
--
Laters

Bill "Solitaire" C

Anáil nathrach, ortha bhas betha, do cheol déanta

jontek2
Posts: 7
Joined: Thu Jul 13, 2017 1:46 pm

Re: Second raspberry pi for subdomain

Fri Jul 14, 2017 10:19 pm

S0litaire wrote:
jontek2 wrote:
S0litaire wrote:take a look at this :

https://serverfault.com/questions/41578 ... t-local-ip

It might be possible without messing about with port numbers, and just use apache/Niginx itself to redirect the sub-domain to another internal IP address
I've tried this but don't get it working. I've have done the following (where domain.com is the exampel URL):

FYI webserver is at 10.0.1.24 and new staging server is on 10.0.1.6

1. cd /etc/apache2/sites-available
2. sudo nano dev.domain.com.conf
3. Pasted in the following:

Code: Select all

<VirtualHost *:80>    
        ServerName dev.domain.com
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>    
        <Location />
                ProxyPass http://10.0.1.6/
                ProxyPassReverse http://10.0.1.6/
        </Location>    
</VirtualHost>
4. sudo a2ensite dev.domain.com.conf
5. sudo systemctl restart apache2

What's happining now is that dev.domain.com gives connection refused and my current domain.com and http://www.domain.com also stops working.

Help :-)
Have got installed the proxypass module for Apache??

https://www.digitalocean.com/community/ ... -extension
Followed this guide and installed/activated the modules. But that made both www.domain.com, domain.com and dev.domain.com go down (503 service unavailable).

I feel like it's something off in the dev.domain.com.conf?

jontek2
Posts: 7
Joined: Thu Jul 13, 2017 1:46 pm

Re: Second raspberry pi for subdomain

Sat Jul 15, 2017 12:39 am

Finally got it working. This was the trick:

Code: Select all

<VirtualHost *:80>
ServerName beta.example.com
ProxyPass / http://192.168.1.102/
ProxyPassReverse / http://192.168.1.102/
</VirtualHost>

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
</VirtualHost>

Return to “Beginners”