we're using php-fpm and have trouble getting the scripts to work if we change the 'root' value in nginx.conf.
location ~ \.php$ {
root /usr/share/nginx/html ;
If we change that root to point to other directory, even if it's /usr/share/nginx/html/crap, it wouldn't work. The directory exists of course. It's like it can read the file in that directory, but not execute it. I've checked all file permissions. Anyone has any idea?
Config which you provided in question will serve php files as a static file with root "root". "root" directive affects only static data.
php-fpm is a fastcgi process manager for php. For fastcgi in nginx there is a bundle of paramters starts with "fastcgi_" prefix.
If you use php-fpm, you probably want php scripts be executed by php-fpm worker. So, nginx should fastcgi_pass requests that addressed to php, to apropriate php-fpm pool.
Something like
can you give more info on your nginx setup ie do you have vhosts or just one site. if vhosts are you using sited-enabled, sites-available setup or similar. it might be easier to so this and just include the locations for sited-enabled like so "include /usr/local/nginx/sites-enabled/*;" in nginx config then create the two folders with a vhost file in one with specific rewrite rules etc and then ln -s it into the sited-enabled folder. the vhost files can point to a folder in your home directory for example and you shouldnt have any permissions problems etc. this wont help with the npm setup but should point you in the right direction re initial setup and config of nginx