How does CGI recognize the compiler?

This question may seem silly to most enlightened people here. But believe me, I ask about it because I could not find the answer with the usual google search and thus resorted to here. I know that CGI is a language agnostic. Since I am not involved in web development, I am just wondering how the web server knows which compiler should look if we have several cgi scripts, among which may be a python script, while others may be C, etc. . Etc.

+4
source share
2 answers

There is nothing in CGI. Each web server does it differently. For example, Apache has a complete configuration language for specifying how to process, filter, and route requests to processors. In contrast, simple python, a simple HTTP server, has no concept of CGI scripts and simply calls methods on the python object to serve requests.

EDIT:

CGI usually means RFC 3875 . This document never requires web servers to associate files in the local file system with URLs.

The bit that comes closest to talking about scripts,

3.4. Performance

The script is invoked in a systematic way.

which basically allows servers to delegate scripts if they like or do something else that they like to serve requests.

+1
source

CGI scripts are run by the operating system.

Usually web servers assume that the file is a CGI script if it is located in a specific directory (often called cgi-bin ) and has an executable bit.

If the web server considers the file to be a CGI script, it fork s, sets some environment variables and other little things, and then asks the operating system to execute it.

The operating system sees if it can execute it directly, and if so, it will happen. Otherwise, it searches for hashbang and uses this to execute the script.

+2
source

Source: https://habr.com/ru/post/1395147/


All Articles