None of the configurations that I've looked up can help with setting up Nginx to serve PHP files on a mounted USB folder. I'm currently getting file not found when I try and access a PHP file on the USB but PHP displays correctly when accessing it on the default folder /usr/share/nginx/www.

In other words, If I have a test.php in /media/usb/downloads/ and try to access sitename.com/usb/test.php I get file not found. But, if i place it in /usr/share/nginx/www/ it works. In both cases, static files work fine.

I have installed nginx and php5-fpm with defaults but added the following changes:


location /usb/ {
    alias /media/usb/downloads/;
    autoindex on;
    allow ::1;
    #deny all;

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
  • Concretely are you saying that if you attempt to access /usb/file.php and /media/usb/downloads/file.php exists, you receive find not found? Are you able to access static files in the directory? Commented Sep 20, 2012 at 18:30
  • Yes... I'll update the question.
    – Andres
    Commented Sep 20, 2012 at 19:06
  • This doesn't seem to be related to the Raspberry Pi...?
    – Jivings
    Commented Sep 20, 2012 at 19:38
  • I agree with @Jivings, is this a configuration that you can validate on other hardware? I wonder if there is a conflict with sitename.com/usb/test.php matching both location directives. Commented Sep 20, 2012 at 20:31
  • On another note, check your logs of nginx, most of the time they contain way more information then the default error message displayed in your browser (if they are useful update your question). Else I agree with @Jivings and HeatfanJohn
    – DanFritz
    Commented Sep 20, 2012 at 22:24

2 Answers 2


Although not ideal since this is circumventing ngnix configuration, using a symbolic link (ln -s) inside the default www root works. For example, using the default config and from the default www folder:

/usr/share/nginx/www $ sudo ln -s /media/usb/downloads/ usb

Thanks!! https://unix.stackexchange.com/questions/48734/nginx-php5-fpm-htdocs-on-usb


I just wanted to point out something here.

Today, when I tried to configure nginx to serve PHP files on my Raspberry Pi Zero (Rpi0) running on Kali Linux OS, I noticed most of tutorials out there I found are mostly based on an old php5-fpm package. In my case, when I tried to install php-fpm package using apt-get install php-fpm, apt-get installed the newest one, i.e. php7.2-fpm package. So, I had to make sure all the nginx configuration for my virtual hosts reflect to the php7.2-fpm and not php5-fpm package as most tutorials call for.

I hope that will help you to get started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.