
我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
。
nginx 中是否有任何指令可以取代$fastcgi_script_name
取得不帶副檔名的腳本名稱?
答案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;
}