https://en.wikipedia.org/wiki/Gateway_(telecommunications)php
In telecommunications, the term gateway refers to a piece of networking hardware that has the following meaning:html
Gateways, also called protocol converters, can operate at any network layer. The activities of a gateway are more complex than that of the router or switch as it communicates using more than one protocol.[citation needed]node
Both the computers of Internet users and the computers that serve pages to users are host nodes, while the nodes that connect the networks in between are gateways. For example, the computers that control traffic between company networks or the computers used by internet service providers (ISPs) to connect users to the internet are gateway nodes.python
In the network for an enterprise, a computer server acting as a gateway node is often also acting as a proxy server and a firewall server. A gateway is often associated with both a router, which knows where to direct a given packet of data that arrives at the gateway, and a switch, which furnishes the actual path in and out of the gateway for a given packet.web
On an Internet Protocol (IP) network, clients should automatically send IP packets with a destination outside a given subnet mask to a network gateway. A subnet mask defines the IP range of a private network. For example, if a private network has a base IP address of 192.168.0.0 and has a subnet mask of 255.255.255.0, then any data going to an IP address outside of 192.168.0.X will be sent to that network's gateway. While forwarding an IP packet to another network, the gateway might or might not perform Network Address Translation.shell
A gateway is an essential feature of most routers, although other devices (such as any PC or server) can function as a gateway.數據庫
Most computer operating systems use the terms described above. Microsoft Windows, however, describes this standard networking feature as Internet Connection Sharing, which acts as a gateway, offering a connection between the Internet and an internal network. Such a system might also act as a DHCP server. Dynamic Host Configuration Protocol (DHCP) is a protocol used by networked devices (clients) to obtain various parameters necessary for the clients to operate in an Internet Protocol (IP) network. By using this protocol, system administration workload greatly decreases, and devices can be added to the network with minimal or no manual configurations.apache
https://zh.wikipedia.org/wiki/網關瀏覽器
網關(英語:Gateway),大陸譯做「網關」、臺灣及香港譯做「閘道器」,區別於路由器(因爲歷史的緣由,許多有關TCP/IP的文獻曾經把網絡層使用的路由器(英語:Router)稱爲網關,在今天不少局域網採用都是路由來接入網絡,所以如今一般指的網關就是路由器的IP),常常在家庭中或者小型企業網絡中使用,用於鏈接局域網和Internet。 網關也常常指把一種協議轉成另外一種協議的設備,好比語音網關。緩存
在傳統TCP/IP術語中,網絡設備只分紅兩種,一種爲網關(gateway),另外一種爲主機(host)。網關能在網絡間轉遞數據包,但主機不能轉送數據包。在主機(又稱終端系統,end system)中,數據包需通過TCP/IP四層協議處理,可是在網關(又稱中介系統,intermediate system)只須要到達網際層(Internet layer),決定路徑以後就能夠轉送。在當時,網關(gateway)與路由器(router)尚未區別。
在現代網絡術語中,網關(gateway)與路由器(router)的定義不一樣。網關(gateway)能在不一樣協議間移動數據,而路由器(router)是在不一樣網絡間移動數據,至關於傳統所說的IP網關(IP gateway)。
網關顧名思義就是鏈接兩個網絡的設備,對於語音網關來講,他能夠鏈接PSTN網絡和以太網,這就至關於VOIP,把不一樣電話中的模擬信號經過網關而轉換成數字信號,並且加入協議再去傳輸。在到了接收端的時候再經過網關還原成模擬的電話信號,最後才能在電話機上聽到。
對於以太網中的網關只能轉發三層以上數據包,這一點和路由是同樣的。而不一樣的是網關中並無路由表,他只能按照預先設定的不一樣網段來進行轉發。網關最重要的一點就是端口映射,子網內用戶在外網看來只是外網的IP地址對應着不一樣的端口,這樣看來就會保護子網內的用戶。
https://en.wikipedia.org/wiki/Common_Gateway_Interface
https://zh.wikipedia.org/wiki/通用網關接口
Each Web server runs HTTP server software, which responds to requests from Web browsers. Generally, the HTTP server has a directory (folder), which is designated as a document collection — files that can be sent to Web browsers connected to this server.[6] For example, if the Web server has the domain nameexample.com
, and its document collection is stored at /usr/local/apache/htdocs
in the local file system, then the Web server will respond to a request forhttp://example.com/index.html
by sending to the browser the (pre-written) file /usr/local/apache/htdocs/index.html
.
CGI extends this system by allowing the owner of the Web server to designate a directory within the document collection as containing executable scripts (or binary files) instead of pre-written pages; this is known as a CGI directory. For example, /usr/local/apache/htdocs/cgi-bin
could be designated as a CGI directory on the Web server. If a Web browser requests a URL that points to a file within the CGI directory (e.g., http://example.com/cgi-bin/printenv.pl
), then, instead of simply sending that file (/usr/local/apache/htdocs/cgi-bin/printenv.pl
) to the Web browser, the HTTP server runs the specified script and passes the output of the script to the Web browser. That is, anything that the script sends to standard output is passed to the Web client instead of being shown on-screen in a terminal window.
The CGI system also allows the Web browser to send information to the script via the URL or an HTTP POST request. If a slash and additional directory name(s) are appended to the URL immediately after the name of the script, then that path is stored in the PATH_INFO
environment variable before the script is called. If parameters are sent to the script via an HTTP GET request (a question mark appended to the URL, followed by param=value pairs), then those parameters are stored in the QUERY_STRING
environment variable before the script is called. If parameters are sent to the script via an HTTP POST request, they are passed to the script's standard input. The script can then read these environment variables or data from standard input and adapt to the Web browser's request.[7]
實現維基百科編輯的CGI程序的一個例子:首先用戶代理程序向這個CGI程序請求某個名稱的條目,若是該條目頁面存在,CGI程序就會去獲取那個條目頁面的原始數據,而後把它轉換成HTML並把結果輸出給瀏覽器;若是該條目頁面不存在,CGI程序則會提示用戶新建一個頁面。全部維基操做都是經過這個CGI程序來處理的。
CGI的工做方式,從Web服務器的角度看,是在特定的位置(好比:http://www.example.com/wiki.cgi)定義了能夠運行CGI程序。當收到一個匹配URL的請求,相應的程序就會被調用,並將客戶端發送的數據做爲輸入。程序的輸出會由Web服務器收集,並加上合適的檔頭,再發送回客戶端。
通常每次的CGI請求都須要新生成一個程序的副原本運行,這樣大的工做量會很快將服務器壓垮,所以一些更有效的技術像mod_perl,可讓腳本解釋器直接做爲模塊集成在Web服務器(例如:Apache)中,這樣就能避免重複載入和初始化解釋器。不過這只是就那些須要解釋器的高級語言(即解釋語言)而言的,使用諸如C一類的編譯語言則能夠避免這種額外負荷。因爲C及其餘編譯語言的程序與解釋語言程序相比,前者的運行速度更快、對操做系統的負荷更小,使用編譯語言程序是可能達到更高執行效率的,然而由於開發效率等緣由,在目前直譯性語言仍是最合適的。
若是代碼只是偶爾改變的話,咱們能夠在服務器產生一個新的進程在編譯代碼以前進行處理。有一個例子是FastCGI,固然還包括其它編寫的加速器,它會在第一次調用腳本時,在系統的某個地方保存腳本編譯過的版本。這樣對這個文件之後的請求就會自動轉向這個編譯過的代碼,而不用每次調用腳本解釋器來解釋腳本。當更改了腳本,加速器的臨時緩存會被清空來保證調用的是新的版本的腳本。
另外一個方法是直接把解釋器放在Web服務器中,這樣就無須新建一個進程來執行腳本。Apache服務器有不少這樣的模塊,像mod_cplusplus、mod_perl、mod_php、mod_python、mod_ruby、和mod_mono。
A Web server that supports CGI can be configured to interpret a URL that it serves as a reference to a CGI script. A common convention is to have a cgi-bin/
directory at the base of the directory tree and treat all executable files within this directory (and no other, for security) as CGI scripts. Another popular convention is to use filename extensions; for instance, if CGI scripts are consistently given the extension .cgi
, the web server can be configured to interpret all such files as CGI scripts. While convenient, and required by many prepackaged scripts, it opens the server to attack if a remote user can upload executable code with the proper extension.[citation needed]
In the case of HTTP PUT or POSTs, the user-submitted data are provided to the program via the standard input. The Web server creates a subset of theenvironment variables passed to it and adds details pertinent to the HTTP environment.
CGI is often used to process inputs information from the user and produce the appropriate output. An example of a CGI program is one implementing a Wiki. The user agent requests the name of an entry; the Web server executes the CGI; the CGI program retrieves the source of that entry's page (if one exists), transforms it into HTML, and prints the result. The web server receives the input from the CGI and transmits it to the user agent. If the "Edit this page" link is clicked, the CGI populates an HTML textarea
or other editing control with the page's contents, and saves it back to the server when the user submits the form in it.
Calling a command generally means the invocation of a newly created process on the server. Starting the process can consume much more time and memory than the actual work of generating the output, especially when the program still needs to be interpreted or compiled. If the command is called often, the resulting workload can quickly overwhelm the server.
The overhead involved in process creation can be reduced by techniques such as FastCGI that "prefork" interpreter processes, or by running the application code entirely within the web server, using extension modules such as mod_perl or mod_php. The overhead can be reduced further by using compiled CGI programs, such as those in C/C++, rather than using Perl or other interpreted languages, and possibly embedding the result in the web server as a specialist module.
Several approaches can be adopted for remedying this:
The optimal configuration for any Web application depends on application-specific details, amount of traffic, and complexity of the transaction; these tradeoffs need to be analyzed to determine the best implementation for a given task and time budget.
CGI程序能夠是Python腳本,PERL腳本,SHELL腳本,C或者C++程序等。
http://www.jdon.com/idea/cgi.htm
CGI腳本簡單地講是個運行在Web服務器上的程序, 有瀏覽器的輸入觸發. 這個腳本一般象服務器和系統中其餘程序如數據庫的橋樑。
CGI 腳本難道不是一個真正的腳本?按照你的服務器的支持, 他們多是一個編譯好的程序或者批命令文件或者其餘可執行的東西. 爲了簡單起見,咱們統稱他們爲腳本scripts.
CGI 腳本是任何運行在web服務器上的程序. CGI意思是Common Gateway Interface。
CGI腳本是用下列兩種方法使用的: 做爲一個表單的ACTION 或 做爲一個頁中的直接link。
CGI腳本由服務器調用, 基於瀏覽器的數據輸入. 其工做原理以下:
https://docs.python.org/3/library/cgi.html
A CGI script is invoked by an HTTP server, usually to process user input submitted through an HTML <FORM>
or <ISINDEX>
element.
Most often, CGI scripts live in the server’s special cgi-bin
directory. The HTTP server places all sorts of information about the request (such as the client’s hostname, the requested URL, the query string, and lots of other goodies) in the script’s shell environment, executes the script, and sends the script’s output back to the client.
The script’s input is connected to the client too, and sometimes the form data is read this way; at other times the form data is passed via the 「query string」 part of the URL. This module is intended to take care of the different cases and provide a simpler interface to the Python script. It also provides a number of utilities that help in debugging scripts, and the latest addition is support for file uploads from a form (if your browser supports it).
The output of a CGI script should consist of two sections, separated by a blank line. The first section contains a number of headers, telling the client what kind of data is following. Python code to generate a minimal header section looks like this: