Join the community today
Register Now

Nginx : How to set a different document root (to external USB drive)

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by VIP_Hawaii, Aug 18, 2016.

  1. VIP_Hawaii

    VIP_Hawaii Member

    34
    6
    8
    May 6, 2016
    Ratings:
    +7
    Local Time:
    4:52 PM
    1.11.3
    10.1.13 (?)
    Unfortunately, I am at this point forced to use an external HDD to serve my web pages from (Nginx document root). However, when I change the root directory in /usr/local/nginx/conf/nginx.conf.default from the default ("home") to /mnt/win/www/html (verifiably where the external USB drive IS mounted) , nothing changes. I have searched through /usr/local/nginx/conf/nginx.conf and the other files in /usr/local/nginx/conf/conf.d yet I see no way to get it to use my external fstab-mounted external USB drive as document root.

    The external drive (a 4 TB Western Digital My Book 1230 USB 3.0 drive set up as an NTFS drive) is already entered in correctly as /dev/sdb1 in /etc/fstab and mounts fine to /mnt/win and is fully accessible in Nautilus (ntfs-3g, ntfs-3g-devel and ntfsprogs are installed as well of course), so that's not a problem.

    In case it matters, I am running CentOS 7.2.1511 64bit with the latest Centminmod beta 009, downloaded and installed last night. (Yay! thanks eva2000, you were right of course, FFMPEG-PHP installed perfectly again with the new betainstaller.sh! ).

    This may have been published somewhere here on this forum but a diligent search could not find it for me (so I created a clear Subject line in this post so it may be findable here in the future!)

    Can anyone help with this?

    TIA,

    VIP Hawaii
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,935
    6,568
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,748
    Local Time:
    11:52 PM
    Nginx 1.13.x
    MariaDB 5.5
    Getting Started Guide and Nginx add vhost page outline where each web hosts config files are as does Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS

    also each centmin.sh menu option 2 created nginx vhost also lists at end of routine the paths including path to log file for the run i.e.

    Code (Text):
    -------------------------------------------------------------
    FTP hostname : IPADDR
    FTP port : 21
    FTP mode : FTP (explicit SSL)
    FTP Passive (PASV) : ensure is checked/enabled
    FTP username created for newdomain10.com : ftpusername
    FTP password created for newdomain10.com : ****
    -------------------------------------------------------------
    vhost for newdomain10.com created successfully
    
    domain: http://newdomain10.com
    vhost conf file for newdomain10.com created: /usr/local/nginx/conf/conf.d/newdomain10.com.conf
    
    vhost ssl for newdomain10.com created successfully
    
    domain: https://newdomain10.com
    vhost ssl conf file for newdomain10.com created: /usr/local/nginx/conf/conf.d/newdomain10.com.ssl.conf
    /usr/local/nginx/conf/ssl_include.conf created
    Self-signed SSL Certificate: /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.crt
    SSL Private Key: /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.key
    SSL CSR File: /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.csr
    Backup SSL Private Key: /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com-backup.key
    Backup SSL CSR File: /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com-backup.csr
    
    upload files to /home/nginx/domains/newdomain10.com/public
    vhost log files directory is /home/nginx/domains/newdomain10.com/log
    
    -------------------------------------------------------------
    Current vhost listing at: /usr/local/nginx/conf/conf.d/
                       
    Aug 11  11:43   846    ssl.conf
    Aug 11  11:43   1.1K   demodomain.com.conf
    Aug 11  11:52   1.6K   virtual.conf
    Aug 12  14:04   2.2K   newdomain10.com.conf
    Aug 12  14:04   3.9K   newdomain10.com.ssl.conf
    
    -------------------------------------------------------------
    Current vhost ssl files listing at: /usr/local/nginx/conf/ssl/newdomain10.com
                       
    Aug 12  14:03   1.7K   newdomain10.com.key
    Aug 12  14:03   1.1K   newdomain10.com.csr
    Aug 12  14:03   1.3K   newdomain10.com.crt
    Aug 12  14:03   1.7K   newdomain10.com-backup.key
    Aug 12  14:03   1.1K   newdomain10.com-backup.csr
    Aug 12  14:03   45     hpkp-info-primary-pin.txt
    Aug 12  14:03   45     hpkp-info-secondary-pin.txt
    Aug 12  14:04   424    dhparam.pem
    
    -------------------------------------------------------------
    Commands to remove newdomain10.com
    
    pure-pw userdel ftpusername
    rm -rf /usr/local/nginx/conf/conf.d/newdomain10.com.conf
    rm -rf /usr/local/nginx/conf/conf.d/newdomain10.com.ssl.conf
    rm -rf /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.crt
    rm -rf /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.key
    rm -rf /usr/local/nginx/conf/ssl/newdomain10.com/newdomain10.com.csr
    rm -rf /usr/local/nginx/conf/ssl/newdomain10.com
    rm -rf /home/nginx/domains/newdomain10.com
    service nginx restart
    -------------------------------------------------------------
    vhost for newdomain10.com setup successfully
    newdomain10.com setup info log saved at:
    /root/centminlogs/centminmod_1.2.3-eva2000.09.001_120816-140252_nginx_addvhost.log
    -------------------------------------------------------------
     
  3. VIP_Hawaii

    VIP_Hawaii Member

    34
    6
    8
    May 6, 2016
    Ratings:
    +7
    Local Time:
    4:52 PM
    1.11.3
    10.1.13 (?)
    Thanks again for the speedy and accurate reply. Yes, I figured it must be in the vhost files ... the reason I did not see the vhost files there is that they had not yet been created; I am just lately getting used to having three real domain names all pointing to the same server; apparently I would create a vhost for all three domains so that http / https requests directed toward a particular domain will automatically be served out of the correct document root directory for that domain ... (?).

    VIP

     
  4. eva2000

    eva2000 Administrator Staff Member

    28,935
    6,568
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,748
    Local Time:
    11:52 PM
    Nginx 1.13.x
    MariaDB 5.5
    yup see Getting Started Guide step 2 and Nginx add vhost page
     
    • Like Like x 1
  5. eva2000

    eva2000 Administrator Staff Member

    28,935
    6,568
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,748
    Local Time:
    11:52 PM
    Nginx 1.13.x
    MariaDB 5.5
    might be easier to symlink the centmin mod paths to your USB drive ?
     
  6. eva2000

    eva2000 Administrator Staff Member

    28,935
    6,568
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,748
    Local Time:
    11:52 PM
    Nginx 1.13.x
    MariaDB 5.5
    haven't done it myself but to symlink try to backup the default permissions just in case

    Code (Text):
    cd /etc/centminmod
    getfacl -R -L --absolute-names /usr/local/nginx/html > backup-usr-local-nginx-html-permissions.acl
    getfacl -R -L --absolute-names /home/nginx > backup-home-nginx-permissions.acl
    

    symlinks
    Code (Text):
    ln -s /mnt/win/www/html /usr/local/nginx/html
    ln -s /mnt/win/www/nginx /home/nginx
    

    fyi, in future to recreate /home/nginx if you need to use below commands as root user in SSH
    Code (Text):
    umask 027
    mkdir -p /home/nginx/domains
    mkdir -p /home/nginx/domains/demodomain.com/{public,private,log,backup}
    chown -R nginx:nginx /home/nginx
    chmod g+s /home/nginx
    chmod g+s /home/nginx/domains/
    umask 022
    

    restoring permissions is just
    Code (Text):
    cd /etc/centminmod
    setfacl --restore=backup-usr-local-nginx-html-permissions.acl
    setfacl --restore=backup-home-nginx-permissions.acl
    
     
  7. VIP_Hawaii

    VIP_Hawaii Member

    34
    6
    8
    May 6, 2016
    Ratings:
    +7
    Local Time:
    4:52 PM
    1.11.3
    10.1.13 (?)
    Well, first I created all three domain name vhosts (using centmin.sh option number 2) including FTP account and SSL certs, thenI followed your symlink instructions from this thread to the letter. So far this has worked perfectly!

    I tried using CloudFlare, and, although it seems to provide a good layer of protection against hackers, it also forms a barrier between your own server and the world wide web, so you wind up wondering 'is there a problem with my website or routing, ... or is CloudFlare (or bad CloudFlare configuration) messing this up'? ... I decided I don't want to have to ask that question anymore, and after having been to CloudFlare Watch and having seen just how un-fulfilled CloudFlare's advertisement of IP privacy actually goes ... so I have now re-commented the Cloudflare include line in my Nginx domain vhost config files, and set up my DNS to be handled by GoDaddy again.

    Thanks again for your help, now this question has been simply and accurately answered for all and is hopefully now very easy to find (it has probably been answered before but I could not find it despite my better-than-average searching ability).


    VIP

     
    • Like Like x 1
  8. eva2000

    eva2000 Administrator Staff Member

    28,935
    6,568
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,748
    Local Time:
    11:52 PM
    Nginx 1.13.x
    MariaDB 5.5
    excellent .. enjoy :)