nginx の拡張子なしのファイル名 SCRIPT_FILENAME

nginx の拡張子なしのファイル名 SCRIPT_FILENAME

私は と の両方phpの実行ファイルを 経由で提供しますnginx。したがって、 をリクエストURLの拡張子で分離します。

location ~ \.php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

location ~ \.c$ {
fastcgi_pass  unix:/var/run/fcgiwrap.socket;
fastcgi_index  index;
fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

の場合PHP、実行するスクリプト.phpには拡張子が付きますが、実行可能ファイルの場合、.hello.cは元のスクリプトであり、コンパイルされた実行可能ファイルはhelloファイルです。

hello訪問時にファイルを実行する必要がありますhttps://example.com/hello.c

$fastcgi_script_name拡張子なしでスクリプト名を取得する代わりに、nginx にディレクティブはありますか?

答え1

その場所でそれをキャプチャします。

例えば:

location ~ ^(.*)\.c$ {
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    fastcgi_index  index;
    include /etc/nginx/fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$1;
}

関連情報