nginx:for_php_fpm
目次
PHP-FPMと構築した場合の設定
ドキュメントルート配下にphpファイルを設置
# vi /usr/share/nginx/html/index.php <?php phpinfo();
⇒以下の設定が必要(基本設定)
# diff /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
30,36c30,36
< location ~ \.php$ {
< root /usr/share/nginx/html; ## ドキュメントルートの定義
< fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; ## php-fpmとソケットで通信
< fastcgi_index index.php;
< fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
< include fastcgi_params;
< }
---
> #location ~ \.php$ {
> # root html;
> # fastcgi_pass 127.0.0.1:9000;
> # fastcgi_index index.php;
> # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
> # include fastcgi_params;
> #}
ドキュメントルート配下にディレクトリを作成してphpファイルを設置
# mkdir /usr/share/nginx/html/test # vi /usr/share/nginx/html/test/date.php <?php var_dump(time());
⇒基本設定以外、特に対応の必要なし
システムでシンボリックリンクを作成
# mkdir /tmp/tmp # ln -fns /tmp/tmp /usr/share/nginx/html/ # vi /tmp/tmp/index.php <?php phpinfo();
⇒基本設定以外、特に対応の必要なし
nginxのaliasを設定してphpファイル設置
# mkdir /tmp/ali # vi /tmp/ali/date.php <?php var_dump(time());
⇒以下の設定が必要
# diff /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
<
< location /ali/ {
< alias /tmp/ali/;
< index index.php index.html index.htm;
<
< location ~ \.php$ {
< fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
< fastcgi_index index.php;
< fastcgi_split_path_info ^/ali(.+\.php)(.*)$;
< fastcgi_param SCRIPT_FILENAME /tmp/ali$fastcgi_script_name;
< include fastcgi_params;
< }
< }
nginx/for_php_fpm.txt · 最終更新: 2025/02/16 13:53 by 127.0.0.1
