Dateiname ohne Erweiterung in nginx SCRIPT_FILENAME

Dateiname ohne Erweiterung in nginx SCRIPT_FILENAME

Ich liefere sowohl phpausführbare Dateien als auch nginx. Daher trenne ich die durch die Erweiterung der Anfrage-URL als

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;
}

Bei PHPhat das auszuführende Skript .phpdie Erweiterung ; bei ausführbaren Dateien .hello.cist jedoch das Originalskript und seine kompilierte ausführbare Datei ist hellodie Datei .

Ich muss die helloDatei beim Besuch ausführen https://example.com/hello.c.

Gibt es in Nginx eine Direktive, die es ermöglicht, $fastcgi_script_nameden Skriptnamen ohne Erweiterung abzurufen?

Antwort1

Halten Sie es vor Ort fest.

Zum Beispiel:

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

verwandte Informationen