简体   繁体   中英

File not found error from nginx on a virtual machine where /var/www/ is mounted from host file structure

I am trying to set up a rather complex development environment as a virtual Ubuntu 12.04 server.

In order that I can edit files and immediately see the change at the refresh of the page as you would expect with a normal local development situation, I have the php source code on the host operating system (mint 14) in ~/www/site1 which I have added as a persistent shared folder to virtualbox and then mount on the virtual machine

mount -t vboxsf site1 /var/www

if I ls /var/www -la I see all the php files but when I try to access the virtual machine from the browser, I get File not found errors on the page and the error.log for the subdomain reports FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream" . The exception is the subdomain phpmyadmin.virtualmachine which loads up perfectly so I know that nginx is serving the correct file structure for the requested subdomain.

As a test I created a subdomain info.virtualmachine which points to /var/test and the index.php is the simplest phpinfo() and this works so I can only presume that nginx is not reading the mounted vboxsf file structure /var/www correctly as all "local" files on the guest OS are viewable.

Nginx has been configured to run as root as have all other services. Is this a known bug with nginx or something that I need to configure to allow nginx to see the mounted vboxsf share?

I found the answer to this and it turned out to be due to file permissions and my unfamiliarity of how php-fpm works.

For starters, I enabled the root user in the virtual server and using supervisord to control the daemons, I set them all to run as root. The parent process for php-fpm runs as root but all child processes were running as www-data. Mounting the share as root caused the folder to be unavailable to php-fpm's child processes which caused nginx to throw file not found errors and because of the way the vboxsf works, I was unable to chown or chmod the share.

I got around this issue by adding the share to /etc/fstab with the following command :

sharename     /var/www     vboxsf    rw,uid=33,gid=33     0      0

this allowed the share to be mounted under the www-data user giving read permissions to www-data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM