× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

HOW TO: Hosting multiple websites

devbobo
Aspirant

HOW TO: Hosting multiple websites

G'day Guys,

For some time I've wanted to host multiple websites from a single ReadyNAS unit...I haven't had the time to investigate it.

1. Backup all the .conf files in /etc/frontview/apache
2. Backup all the .conf files in /etc/frontview/apache - so you can restore the originals if you screw something up !!!

3. Edit /etc/frontview/apache/Virtual.conf

Original file

<VirtualHost _default_:80>
SSLEngine off
RewriteEngine on

RewriteRule ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]
</VirtualHost>

Modified file

NameVirtualHost *:80

<VirtualHost *:80>
SSLEngine off
RewriteEngine on

RewriteRule ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]
</VirtualHost>

4. Create a new my-virtual.conf file in /etc/frontview/apache/addons, this way it will be auto loaded without modifying any other files. The example below has definitions for two websites....add/remove as required.

my-virtual.conf

<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /path/to/example.com
<Directory /path/to/example.com>
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>

<VirtualHost *:80>
ServerName www.domain.net
DocumentRoot /path/to/domain.net
<Directory /path/to/domain.net>
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>


5. shutdown apache, killall apache-ssl
6. restart apache, apache-ssl -f /etc/frontview/apache/httpd.conf
7. All done 😄

CAVEATS
1. Toggling the state of HTTP within Frontview rewrites Virtual.conf so the above changes will be lost.

ReadyNAS Team
1. It would be nice if the above changes could be made to the format of /etc/frontview/apache/Virtual.conf, so that changes aren't overwritten
2. I currently have to add the Location element to undo a global definition within httpd.conf. It would be awesome if this was removed from httpd.conf and added to Virtual.conf as...

NameVirtualHost *:80

<VirtualHost *:80>
<Location /index.html>
SetHandler server-status
Order Deny,Allow
Deny from all
</Location>
SSLEngine off
RewriteEngine on

RewriteRule ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]
</VirtualHost>


Cheers,

David
Message 1 of 130
super_poussin
Virtuoso

Re: HOW TO: Hosting multiple websites

why not using /etc/frontview/apache/addons/ for this ?
Message 2 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

super-poussin wrote:
why not using /etc/frontview/apache/addons/ for this ?


Step 4 uses that location, however, the way /etc/frontview/apache/Virtual.conf has been defined....it really doesn't allow expansion, hence the reason for modifying it. You can't have mixed declarations of <VirtualHost _default_:80> and <VirtualHost *:80> as the first one declared will always be used.
Message 3 of 130
dbott67
Guide

Re: HOW TO: Hosting multiple websites

Nice how-to... thanks for sharing.

Does this still require these steps?

http://www.readynas.com/?p=135

Currently, I've got my blog-thingy hosted on the ReadyNAS Pro. In Frontview, under the HTTP protocol I am redirecting HTTP traffic to the read-only HTTP share "webserver". How does your how-to fit in with this?



Notice that when you try to go to my site http://home.bott.ca/ in automatically redirects to the webserver share (as I expect it would - http://home.bott.ca/webserver/).

Do all websites have to be placed within this "webserver" share?

I guess I'm just a bit confused as to how this works. If you've got any sites hosted on your NAS where you can provide an example, I'd love to see it in action.

Regards,
Dave
Message 4 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

I don't use that option, I currently have it set to 'None Selected'. Using that options adds an additional rewrite rule to /etc/frontview/apache/Virtual.conf, something like this...

RewriteRule ^/$ /webserver [R,L]

Instead, I have a single share called 'Sites' with a folder for each site that I have configured, then the my-virtual.conf sets the DocumentRoot to the specific Site folder. But I have only done this to make my life easy for updating content. Each site could exist on totally different shares, there is no restriction on that.

I'm not hosting anything elaborate, just some firefox extensions and other stuff that I hack around with, here's two sites that are currently hosted off my NAS...

http://www.smugglr.net
http://smugbrowser.introversion.com.au/beta
Message 5 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

dbott67 wrote:
Nice how-to... thanks for sharing.
Does this still require these steps?
http://www.readynas.com/?p=135


No, actually the approach from this Howto is more flexible but requires more work and a lot more knowledge about how things "really work".

dbott67 wrote:
Currently, I've got my blog-thingy hosted on the ReadyNAS Pro. In Frontview, under the HTTP protocol I am redirecting HTTP traffic to the read-only HTTP share "webserver". How does your how-to fit in with this?

Two totally different beasts.
The way you do it will create a config similar to this:

<VirtualHost _default_:80>
SSLEngine off
RewriteEngine on
RewriteRule ^/$ /website [R,L]

RewriteRule ^/admin/(.*)$ https://%{SERVER_NAME}/admin/$1 [R,L]
</VirtualHost>


The important part is line 4 where all requests are redirected to the Share "website". That's what you already noticed here:

dbott67 wrote:
Notice that when you try to go to my site http://home.bott.ca/ in automatically redirects to the webserver share (as I expect it would - http://home.bott.ca/webserver/).


While this works, it will just allow you to host one website on your NAS.
Comes in the Howto. The important part here is that you can have not only one but several <VirtualHost ...> entries.
This leads straight to your next question:

dbott67 wrote:
Do all websites have to be placed within this "webserver" share?


No. Let's have a look at the VirtualHost definition:
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /path/to/example.com
<Directory /path/to/example.com>
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>


Notice line 3. The DocumentRoot ... tells Apache where to look for the files it should serve to the user. In this case this would be /path/to/example.com
Also important is line 2. The ServerName ... tells Apache what site this configuration is meant for.
A simple, yet very abbreviated example:

<VirtualHost *:80>
ServerName server1.dyndns.org
DocumentRoot /website1
(...)
</VirtualHost>
<VirtualHost *:80>
ServerName anotherserver.dyndns.org
DocumentRoot /website2
(...)
</VirtualHost>

Now what happens when a request comes in is this: Apache will look in the headers for the host name the user wanted to address. Say the user requested "anotherserver.dyndns,org". Apache finds the defintion for that server, looks into the directory /website2 and will serve the file index.html if it's to be found there. (That's an overly simplistic explanation but you should get the drift). /website2 doesn't have to be a share, it just has to exist.
Likewise, since all Apache cares about is the host name, not the IP address, "server1.dyndns.org" and "anotherserver.dyndns.org" may of course point to the same (your public) IP address.

I really hope this was somewhat understandable since I tried to cramp many things in a "not too long to digest" post 😉

-Stefan
Message 6 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

WhoCares? wrote:

No, actually the approach from this Howto is more flexible but requires more work and a lot more knowledge about how things "really work".


Thanks for the explanation for those who don't understand how apache works 😄
Message 7 of 130
mdgm-ntgr
NETGEAR Employee Retired

Re: HOW TO: Hosting multiple websites

Nice how-to. Will need to take a look sometime.
Message 8 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

devbobo wrote:
Thanks for the explanation for those who don't understand how apache works 😄

No problem 😉
The only real problem I see with this is that it opens a huge barn door for people to break FrontView in the process of setting up their websites. And since I'm quite confident that the majority of ReadyNAS users doesn't know how to fix Apache configs, I'll leave the support calls to you 😄

-Stefan
Message 9 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

WhoCares? wrote:
devbobo wrote:
Thanks for the explanation for those who don't understand how apache works 😄

No problem 😉
The only real problem I see with this is that it opens a huge barn door for people to break FrontView in the process of setting up their websites. And since I'm quite confident that the majority of ReadyNAS users doesn't know how to fix Apache configs, I'll leave the support calls to you 😄

-Stefan


That was my primary concern, and that's why I decided to post in this forum. If above changes were made to the Virtual.conf file by the ReadyNAS team....the risk of that happening would be reduced considerably and that would open up the prospect of making this into an Add-on which would remove the risk all together.
Message 10 of 130
mdgm-ntgr
NETGEAR Employee Retired

Re: HOW TO: Hosting multiple websites

devbobo wrote:
That was my primary concern, and that's why I decided to post in this forum. If above changes were made to the Virtual.conf file by the ReadyNAS team....the risk of that happening would be reduced considerably and that would open up the prospect of making this into an Add-on which would remove the risk all together.


You may wish to create a new post in the feature request forum: viewforum.php?f=18

You could state the change you want and point to this thread for the reason why.
Message 11 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

devbobo wrote:
If above changes were made to the Virtual.conf file by the ReadyNAS team....the risk of that happening would be reduced considerably and that would open up the prospect of making this into an Add-on which would remove the risk all together.

Actually I've been playing with the thought myself. But after some consideration I realized, that this will mean a whole shitload (sorry ;)) of additional work to bake this into an addon. Starts with creating the directories, goes on to making sure that the vHost definitions are correct, supporting different DocumentIndex files (like index.php -> checking whether PHP is installed? -> ... ), possibly setting up of shares (which user to give access by default?) and on and on and on. That's why I refrained from posting. So: hat tip to you for being bold 😉

-Stefan
Message 12 of 130
mdgm-ntgr
NETGEAR Employee Retired

Re: HOW TO: Hosting multiple websites

devbobo, if you wish to develop an add-on you can start by looking here: How to Develop a Frontview Add-On

If NetGear doesn't change the config file, you may need to get the add-on to backup the conf files after a change. Then setup a button that results in the conf files being restored from backup.

It'd be a lot of work, but if you want to do it, go for it.
Message 13 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

WhoCares? wrote:
devbobo wrote:
If above changes were made to the Virtual.conf file by the ReadyNAS team....the risk of that happening would be reduced considerably and that would open up the prospect of making this into an Add-on which would remove the risk all together.

Actually I've been playing with the thought myself. But after some consideration I realized, that this will mean a whole shitload (sorry ;)) of additional work to bake this into an addon. Starts with creating the directories, goes on to making sure that the vHost definitions are correct, supporting different DocumentIndex files (like index.php -> checking whether PHP is installed? -> ... ), possibly setting up of shares (which user to give access by default?) and on and on and on. That's why I refrained from posting. So: hat tip to you for being bold 😉

-Stefan


I think you might be over-complicating it (or maybe it's me simplifying it too much)...but for the add-on i had in mind, the user would add the ServerName and DocumentRoot for each website they wanted to host. From info that it should be pretty simple to create to .conf file to put in /etc/frontview/apache/addons. I don't really care about creation of shares etc, that is admin crap that doesn't really have to live in the addon. Am I missing something ? :?
Message 14 of 130
mdgm-ntgr
NETGEAR Employee Retired

Re: HOW TO: Hosting multiple websites

You have to be careful. If people who don't have SSH enabled install the add-on and it stuffs up so that Frontview can't be accessed... then that's not going to be too good.

Hopefully a firmware re-install would get the NAS working again.
Message 15 of 130
devbobo
Aspirant

Re: HOW TO: Hosting multiple websites

mdgm wrote:
devbobo, if you wish to develop an add-on you can start by looking here: How to Develop a Frontview Add-On

If NetGear doesn't change the config file, you may need to get the add-on to backup the conf files after a change. Then setup a button that results in the conf files being restored from backup.

It'd be a lot of work, but if you want to do it, go for it.


thanks, I've already been looking at the doco. Might have a play tonight.
Message 16 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

devbobo wrote:
Am I missing something ? :?

No, not really. Just the thing about "giving the little finger and have your arm torn out". Besides that, I guess you'd be home safe 😄

-Stefan
Message 17 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

mdgm wrote:
Hopefully a firmware re-install would get the NAS working again.

That's one of the problems because most likely it wouldn't.

-Stefan
Message 18 of 130
mdgm-ntgr
NETGEAR Employee Retired

Re: HOW TO: Hosting multiple websites

WhoCares? wrote:
mdgm wrote:
Hopefully a firmware re-install would get the NAS working again.

That's one of the problems because most likely it wouldn't.

-Stefan


Ok. So yeah SSH installed would be a must. Also a simple script to restore default conf files. That could be started by e.g.


/c/script.sh


or whatever you want to call it. That should fix a problem if something goes drastically wrong (I think). If it doesn't then perhaps a script (with files from a working system on the same firmware version) may need to be downloaded.
Message 19 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

mdgm wrote:
Ok. So yeah SSH installed would be a must.

See, there we go. When I started developing addons I was under the impression that it would be clear to users that having SSH enabled was mandatory before installing an addon. Well, turns out I was wrong.


mdgm wrote:
Also a simple script to restore default conf files.

It'd be even easier than that. Just have Netgear modifiy Vhost.conf like suggested and add a line like

Include /etc/frontview/apache/VHost_user.conf


This file could exist as a 0 byte sized file to be filled by the addon. Make sure that a firmware reinstall overwrites the file with the 0 byte sized version and you're ... well ... somewhat safe there.

-Stefan

Edit: Still, I've been thinking about this a lot. And I've always come to the same conclusion: If you can do it, you don't need an addon. If you can't do it ... well, maybe then you shouldn't 😉
Message 20 of 130
dbott67
Guide

Re: HOW TO: Hosting multiple websites

Stefan, thanks for the explanation and to the rest for the enlightening posts. It does make sense and I think I may tinker around a bit when I get some free time. This looks very interesting... 😎
Message 21 of 130
Event_Horizon
Aspirant

Re: HOW TO: Hosting multiple websites

I've been playing around with this for a few weeks and feel I'm almost there but unfortunately it still doesn't work. I've picked up a few skills on the way including using the OSX Terminal and also vi editor. I've modified the file Virtual.conf as detailed in this thread. I've also created a new file called my-virtual.conf which I've saved in the /etc/frontview/apache/addons directory.

my-virtual.conf file is as follows

<VirtualHost *:80>
ServerName www.TheMadamButterfly.co.uk
DocumentRoot /websites/TheMadamButterfly
<Directory /websites/TheMadamButterfly>
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>


<VirtualHost *:80>
ServerName www.GabriellaKingsley.me.uk
DocumentRoot /websites/GabriellaKingsley
<Directory /websites/GabriellaKingsley>
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>

I've created a share to my websites directory on the ReadyNAS. Within the websites director I have two further directories names 'GabriellaKingsley' and 'TheMadamButterfly'. These two directories contain my websites. I have an index.html in both specific to each website. When I type either of the website names into Snow Leopard, it takes me to my shares directory on my ReadyNAS duo. It does not take me to my actual website.

I've changed the setting on HTTP in Services/Standard File Protocol as follows.
Redirect default web access to this share: None Selected

But still I cannot detect either of my two websites. Any suggestions as to what I'm doing wrong.

With regard to the new addon 'my-virtual.conf', I've assumed that this will load automatically, or do I have to load it myself. I cannot see the file under Services/Installed Add-ons. I've rebooted the ReadyNAS and also performed a volume scan but still no luck. This has the potential to be a great add-on if only I can get it to work.
Many Thanks
Phil
Message 22 of 130
dbott67
Guide

Re: HOW TO: Hosting multiple websites

Try setting the path from /websites/TheMadamButterfly to /c/websites/TheMadamButterfly (/c is the data volume and would need to be included in the path). For example:

<VirtualHost *:80>
ServerName www.TheMadamButterfly.co.uk
DocumentRoot /c/websites/TheMadamButterfly
<Directory /c/websites/TheMadamButterfly
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>


<VirtualHost *:80>
ServerName www.GabriellaKingsley.me.uk
DocumentRoot /c/websites/GabriellaKingsley
<Directory /c/websites/GabriellaKingsley
Options Indexes
Order allow,deny
Allow from all
</Directory>
<Location /index.html>
SetHandler none
Order Allow,Deny
Allow from all
</Location>
SSLEngine off
</VirtualHost>



-Dave
Message 23 of 130
WhoCares_
Mentor

Re: HOW TO: Hosting multiple websites

dbott67 wrote:
Try setting the path from /websites/TheMadamButterfly to /c/websites/TheMadamButterfly (/c is the data volume and would need to be included in the path).


SInce the ReadyNAS has the habit of creating symlinks for every share in the / dir, this shouldn't be neccessary. However, it's advisable to use the full path whenever possbile nevertheless.

-Stefan
Message 24 of 130
Event_Horizon
Aspirant

Simple Solution - Hosting multiple websites

The Simple Solutions are always the Best
I've been playing around with this for about a week and just could not get it to work as per the original posting by devbobo. Along the way I learnt to use the Terminal command editor and also the vi editor to modify and create new system files. In frustration I sat down with a large G&T and thought out a few other possible solutions. Luckily for me my first solution worked and it's so simple. It literally took me less than 5 minutes to set up the multiple websites.

Firstly I created a webserver on my ReadyNAS DUO in accordance with these instructions http://www.readynas.com/?p=135
This procedure will allow you to host a single website.

I created a folder in the root directory of my ReadyNAS called websites as detailed in the above procedure. I then re-directed default web access to the 'websites' share in Services/Standard File Protocols in Frontview. Remember the 'websites' share must be read only. Within my 'websites' directory I then created additional directories for my other websites.

I have 3 websites that I am using for a test which you can try out.

Event-Horizon.cc
Event-Horizon.uk.com
EventHorizon.co

I actually include the various suffixes in the directory name so that the site easier to recognise.

Enter www.event-horizon.cc into your browser to try out the first site.

It's not necessary to set up any shares for the other directories, they simply have to exist with of course the appropriate index.html file and other associated files although these are not necessary for a single page website.

I use Web Forwarding in my domain name description to redirect the various website name(s) to my ip address. I then add the full path of my website within this forwarding rule to take it straight to the relevant directory as detailed below.

http://xx.x.xxx.xxx/websites/Event-Horizon.cc

This solution does not require any knowledge of unix commands or editor commands and you do not have to play around with any of the system files.

The major benefit for using the ReadyNAS to host one's website is that you do not have to get involved in ftp and uploading the website to the host server etc.

Best of Luck

Phil
Message 25 of 130
Top Contributors
Discussion stats
Announcements