A
A
Akmat2017-07-11 11:17:03
Python
Akmat, 2017-07-11 11:17:03

How does a webserver and cgi script work?

Wikipedia says about CGI that it is an interface standard for connecting an external program to a web server.
I am a beginner web developer, so I have such questions regarding the web.
I understand that CGI is not a program, it's just an agreed upon protocol for a web server and a cgi script.
Which tells how the web server should start, give http requests to the cgi script and how the cgi script should give the result of processing back to the web server.
This is how I understood the relationship between the web server and the cgi script.
If I misunderstood, please correct me.
Please share your experience.
I don't know how web applications and application architecture are built.
how the web server communicates and different technologies.
At one time, how did you learn the web?
Can you advise me where to start where to move in order to understand the architecture of web applications.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-07-11
@saboteur_kiev

The web server launches the CGI program and passes the environment variables to it with the data that the client passed in the HTTP request.
Depending on what the CGI is written in, it can be extracted.
The infa is sent to the client simply - the CGI script simply writes it to stdout, the web server sends it to the client.
For example, for perl scripts, data from the client is available through $ENV{'VAR_NAME'}, where VAR_NAME is the name of a particular variable. The list can be viewed www.oreilly.com/openbook/cgi/ch02_02.html
The script output should start with content-type, if you output html content, then for example
print "Content-type: text/html\n\n";
Then regular html.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question