Score:1

Filename without extension in nginx SCRIPT_FILENAME

jp flag

I serve both php and executable files via nginx. Thus, I separate the by the extension of request URL as

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

With PHP, the script to run has .php extension; but for executable files, .hello.c is the original script and its compiled executable is hello file.

I need to run the hello file when visiting https://example.com/hello.c.

Is there any directive in nginx instead of $fastcgi_script_name to get the script name without extension?

Score:1
jp flag

Capture it in the location.

For example:

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

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.