Configure FreeNAS To Store Your Apache Web Files

(20140208 – This post has been amended to provided an updated version of the Apache directive — iceflatline)

Over this past summer I had the pleasure of cobbling together a few spare parts in order to build a Network Attached Storage (“NAS”) box based on FreeNAS. This device has more than fulfilled my initial requirements for reliable file storage and media server in my network. This post will describe how I configured this FreeNAS box to store web files and serve as a document root for the Apache http server implemented in my Ubuntu server. This approach places my local web files on a solid, reliable and centralized RAID 5 disk storage system, and provides good logical and physical separation between file storage and file server functionality.

The versions for the software used in this post were as follows:

  • FreeNAS v0.7.1 Shere (revision 5127)
  • Ubuntu Server v10.04 LTS (x64)
  • Apache v2.1.14
  • nfs-common v1:1.2.0-4ubuntu4
  • portmap v6.0.0-1ubuntu2

Configuring the FreeNAS Server

I began by creating the directory www on /mnt/files, an existing mount point. This directory would serve as my new Apache document root. Then, I enabled the Network File System (“NFS”) service in FreeNAS so that /mnt/files/www could be accessed from the Ubuntu server. To do this, navigate to Services->NFS->Settings and make sure that the check box for enabling NFS is checked and specify the number of servers that will run (the default value of four should easily handle dozens of users). Now select “Save and Restart.” Next, navigate to Services->NFS->Shares and select the “+” icon, where you are presented with the configuration screen for creating a new NFS share. Enter the path to be shared; the network that is authorized to access this shared path; and, make sure that the “All dirs” checkbox selected. The remaining options can retain their defaults (See Figure 1). Now select “Add” then “Apply changes.”

Screenshot of NFS shared path configuration in FreeNAS

Figure 1

Configuring the Ubuntu Server

To configure the Ubuntu server I needed to add a couple of packages in order to mount the NFS shared path without error. The nfs-common package is needed when a host acts as an NFS client, and includes a number of processes that ensure a particular NFS connection is allowed and may proceed. Because NFS relies upon remote procedure calls to function, the package portmap is also needed to map RPC requests to the NFS service:

Next, I created a directory so I could mount the NFS shared path. Here you must include the IP address of the FreeNAS server as well as the directory created on it previously:

In order for the shared path to mount automatically at boot time, I added the following lines to the /etc/fstab file:

I made sure the directory permissions were set correctly, and modified the owner and group associated with /media/www so that the Apache http server could access it:

Then edited the /etc/apache2/apache2.conf file, adding an alias for /media/www and a directory directive to the end of the file:

I created an index.html file and moved it to /media/www to test the above configuration, and made sure the file permissions were set correctly:

Finally, I restarted the Apache http server:

Conclusion

This concludes the post on how to configure a FreeNAS server as an Apache document root, providing a reliable way to store your web files, while at the same time utilizing the Ubuntu and Apache servers for what they do best – serving up those files.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

iceflatline