Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question
up vote 1 down vote accepted

I have a strong suspicion that this is happening because the location ~ \.php$ directive is sending the http://sitename.com/usb/index.php request as is to unix:/var/run/php5-fpm.sock and it doesn't find a /usb/ directory on the server.

Have you considered using a link (ln) called usb in our root directory to /media/usb/downloads instead using the location alias?

share|improve this answer
Perfect!! I used a symbolic link and it worked! I wish there was better documentation on how to actually do this through the nginx configuration files. – Andres Sep 21 '12 at 15:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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