Tips / Nginx

How to Install NFS Server on CentOS 6


NFS means Network File System, and it is a great way to share a filesystem across your network and use it mounted on as many computers/servers as you want. The result: you can access a remote local network storage to read, write, and of course even serve your Nginx requests.

On this tutorial I will show you How to install NFS server on CentOS 6, you will also lear how to mount nfs on the remote clients and finally how to serve traffic from NFS using Nginx.


  • 2 servers, one to act as master NFS server and the other to act as client/slave.
  • 100MBit private network (1Gbps is better) between both servers.
  • Nginx installed (if you want to serve files from NFS server).
  • CentOS Linux on each box, if you need a VPS/Dedicated server you can take a look at this two great hosting providers:
    • A Small Orange
    • A2 Hosting

Install NFS server on CentOS 6

yum update -y
yum groupinstall 'Development Tools' -y

On the NFS Server (master) run this commands:

yum install nfs-utils nfs-utils-lib -y

Add the NFS server to boot automatically:

chkconfig nfs on 
chkconfig rpcbind on
service rpcbind start
service nfs start

Export the Shared Directory

Now the next step is to configure which directory will be shared across the client (slaves) servers. It could be /var/www/ /home/user/documents, or whatever you need. Once you have the shared directory in mind, then add it to /etc/exports file, where you can specify the directory to share and its options.

On this example, let’s suppose we want to share /var/www/ and that your CLIENT NFS server is using IP.

nano -w /etc/exports

Add the following lines to the bottom of the file, sharing the directory with the client:


As you see, we specified the shared directory to be /var/www/, the IP allowed to connect to the NFS server is and the last line is showing a few sharing options, let’s explore each one of them:

rw: allow read and write from the client server.
sync: will sync only once changes have been done to the nfs server local directory.
no_root_squash: allows root user to connect to the shared directory.
no_subtree_check: disabling this will speed up transfers, avoid volume check.

Tcpwrappers and Firewall configuration

If you are using tcpwrappers, then add this lines to your /etc/hosts.allow file

nano -w /etc/hosts.allow

Add this inside:

portmap :
lockc :
mountd :
rquotad :
statd :

If you are using iptables firewall, remember to add IP to the whitelist to allow any communication, or run this iptables allow command:

iptables -A INPUT -s -j ACCEPT

On the NFS clients (slaves) run this commands:

yum install nfs-utils nfs-utils-lib

Mount the NFS Shared Directory

Create the shared directory:

mkdir -p /var/www/

Then mount it manually:

mount XX.XX.XX.XX:/var/www/ /var/www/

Replace “” with the private IP of your master server.

Test the NFS mount

df -ah | grep

You should see something like this: 108G 23G 80G 23% /var/www/

Now let’s add the mount point to the /etc/fstab file so it can boot automatically after any reboot: /var/www/ nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

Test it:

mount -a
df -ah

If you see it has been mounted again, then your /etc/fstab entry is working as expected.

Finally, you can use /var/www/ to be served using Nginx, as any other local directory. This is a full example of a simple virtual host working with NFS and PHP-FPM daemon:

nano -w /etc/nginx/conf.d/yoursite.comf

Add this to that file:


server {
access_log off;
log_not_found off;
error_log  /etc/nginx/logs/ warn;

        listen       80;

       location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf)$ {
        root   /var/www/;
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";


        location / {
            root   /var/www/;
            index  index.php index.html index.htm;

# PHP parsing using php-fpm
        location ~ .php$ {
            root           /var/www/;
            try_files $uri =404;
            fastcgi_pass   unix:/tmp/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 4k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;


As you see, installing a NFS server on CentOS 6 is not that hard, and it’s even more easy to use it with Nginx web server.

Popular search terms:

  • oscommerce for centos 6
  • how to install nfs server on centos
  • centos nfs mount
  • install nfs on centos 6

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • miax

    Ok but what with /var/lib/mysql?