###前提・実現したいこと
nginx + PHP-FPM(Socket通信)の環境で、デフォルト以外の任意のディレクトリをDocumentRootにしてPHPを実行したい。
###環境
CentOS(7.4.1708)
nginx(1.12.2)
PHP(7.1.11)
PHP-FPM(7.1.11)
nginxは、公式のStableバージョンをYumで導入
PHP関連は、Remi repositoryからYumで導入
###発生している問題・エラーメッセージ
デフォルト以外のディレクトリをDocumentRootに指定すると、"File not found."と表示され、PHPが実行されない。
また、nginxのlogには以下のようなものが出力される。
error.log
2017/11/13 12:40:57 [error] 1937#1937: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: *.*.*.*, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "*.*.*.*"
access.log
*.*.*.* - - [13/Nov/2017:12:40:57 +0900] "GET /index.php HTTP/1.1" "/tmp/foo"404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36" "-" "/index.php" "/index.php" "/tmp/foo" "/index.php"
###Config
/etc/nginx/nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" "$document_root"' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$request_uri" "$document_uri" "$document_root" "$fastcgi_script_name"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; }
/etc/nginx/conf.d/default.conf
server { listen 80 default_server; root /tmp/foo; location / { index index.php; } location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REQUEST_METHOD $request_method; fastcgi_intercept_errors on; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /tmp/foo; } }
/etc/php-fpm.conf
include=/etc/php-fpm.d/*.conf [global] error_log = /var/log/php-fpm/error.log daemonize = yes
/etc/php-fpm.d/www.conf
[www] user = nginx group = nginx listen.owner = nginx listen.group = nginx listen = /var/run/php-fpm/php-fpm.sock pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 slowlog = /var/log/php-fpm/www-slow.log php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
/tmp/foo/index.php
<?php phpinfo(); ?>
DocumentRootのディレクトリ(/tmp/foo)の権限は、"777"に設定されています。
# ll -d /tmp/foo/ drwxrwxrwx 2 nginx nginx 41 11月 10 20:19 /tmp/foo/
###試したこと
デフォルトのDocumentRoot(/usr/share/nginx/html)や、それをコピーして作成した"/usr/share/nginx/html2"というPathをDocumentRootにすると、正常にPHPが実行される。
また、/tmp/foo/index.htmlというStatic contentsを作成すると、正しく表示される。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/13 11:29