
私は と の両方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;
}