page counter next up previous contents
Next: SAMBA 架設 Up: SELinux 管理 Confined 服務 Previous: NFS Client 端掛載   Contents   DYWANG_HOME

Httpd 使用 NFS

  1. 編輯 httpd 配置檔,將 DocumentRoot 改到 /mnt/nfsmount。
    [root@kvm7 ~]# vim /etc/httpd/conf/httpd.conf 
    [root@kvm7 ~]# grep -A5 ^DocumentRoot /etc/httpd/conf/httpd.conf
    DocumentRoot "/mnt/nfsmount"
    <Directory "/mnt/nfsmount">
        AllowOverride None
        # Allow open access:
        Require all granted
    </Directory>
    
  2. 重新啟動 httpd 服務。
    [root@kvm7 ~]# systemctl restart httpd.service
    
  3. 在 NFS server 的 /public 目錄下新增 index.html。
    [root@kvm5 ~]# cal > /public/index.html
    
  4. 查看 /mnt/nfsmount/index.html 的 SELinux contexts 為 nfs_t
    [root@kvm7 ~]# ls -Z /mnt/nfsmount/
    -rw-r--r--. root root system_u:object_r:nfs_t:s0       index.html
    
  5. curl 訪問網頁,回傳沒有權限存取。
    [root@kvm7 ~]# curl http://127.0.0.1/index.html
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>403 Forbidden</title>
    </head><body>
    <h1>Forbidden</h1>
    <p>You don't have permission to access /index.html
    on this server.</p>
    </body></html>
    
  6. index.html 的 SELinux context 是 nfs_t,必須開啟 httpd_use_nfs 布林值,查看此布林值目前是 off。如果是 cifs_t 則要開啟 httpd_use_cifs 布林值。
    [root@kvm7 ~]# getsebool -a | grep httpd_use_nfs
    httpd_use_nfs --> off
    
  7. 開啟布林值 httpd_use_nfs
    [root@kvm7 ~]# setsebool -P httpd_use_nfs on
    [root@kvm7 ~]# getsebool -a | grep httpd_use_nfs
    httpd_use_nfs --> on
    
  8. curl 再訪問網頁,成功回傳網頁內容。
    [root@kvm7 ~]# curl http://127.0.0.1/index.html
        October 2019    
    Su Mo Tu We Th Fr Sa
           1  2  3  4  5
     6  7  8  9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28 29 30 31
    



De-Yu Wang 2020-05-14