Apache: Add CGI Mode

Source: Internet
Author: User

Final expectation: By configuring Apache CGI, Apache will be able to connect to the GO program via CGI (because our backend program is written in the Go language).

Lab 1:

Expectation: The application can run by configuring CGI.

Go code:

Package Mainimport"FMT"Func Main () {FMT. Println ("content-type:text/plain;\n")                                                                                             forI, J: =0,5; I <= J; I, j = i+1, J-1{// RightFmt. Println ("i="I"; j=", J)}  forI, J: =0,5; I <= J; i++ {// RightFmt. Println ("i="I"; j=", J)} //for i,j: = 0,5; I <= J; i++, j--{//wrong//FMT. Println ("i=", I, "; j=", J)//} }

Go compilation:/usr/local/go/bin/go build-o/home/luwenwei/go/base/main/home/luwenwei/go/base/for.go

The app is ready for you right now.

Apache Configuration:

<VirtualHost*:80> ServerName api.query.soft.360.cn scriptalias//home/luwenwei/go/base/main #ScriptAlias/test-cgi/usr/local/apach e2/cgi-bin/test-cgi<Directory"/usr/local/apache2/cgi-bin/">options-indexes followsymlinks allowoverride None Order deny,allow allow from all 
    </Directory>errorlog logs/error_lww Customlog "|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/lww_access_log.% y%m%d 86400 480 "Combinedio</VirtualHost>

Expect access to http://api.query.soft.360.cn/to output something.

Output:

I=0; j=5I=1; j=4I=2; j=3I=0; j=5I=1; j=5I=2; j=5I=3; j=5I=4; j=5I=5; j=5

The results were in line with expectations and the experiment 1 succeeded.

Lab 2:

There are already test-cgi applications in the Apache bin-cgi directory, and we expect to be able to introduce them smoothly through experiment 1.

Apache Configuration:

<virtualhost *:>                                                                                                                        ServerName api.query.soft.  the . CN     //home/luwenwei/go/base/main    /test-cgi/usr/local/apache2/cgi-bin/test-CGI    Errorlog logs/error_lww    "|/usr/local/apache2/bin/rotatelogs/usr/local/ apache2/logs/lww_access_log.%y%m%d 86400 480"  combinedio</VirtualHost>

Visit http://api.query.soft.360.cn/test-cgi and expect to be able to output some content.

Actual output:

forbiddenyou Don ' T has permission to access/test-cgi on the this server.

The actual discrepancy is expected.

The correct configuration is:

<virtualhost *: the> ServerName Api.query.soft. the. CN #ScriptAlias//home/luwenwei/go/Base/main Scriptalias/test-cgi/usr/local/apache2/cgi-bin/test-CGI<directory"/usr/local/apache2/cgi-bin/">Options-Indexes followsymlinks allowoverride None Order deny,allow allow from All</Directory>errorlog Logs/ERROR_LWW Customlog"|/usr/local/apache2/bin/rotatelogs/usr/local/apache2/logs/lww_access_log.%y%m%d 86400 480"Combinedio</VirtualHost>

Normal access after FollowSymLinks is configured. The page output is:

cgi/1.0 test Script REPORT:ARGC is 0. ARGV is. Server_software = Apacheserver_name = Api.query.soft.360.cngateway_interface = Cgi/1.1server_protocol = HTTP/1.1SERVER _port = 80request_method = Gethttp_accept = text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q= 0.8path_info = path_translated = Script_name =/test-cgiquery_string = Remote_host =remote_addr = 10.18.32.50REMOTE_USER = Auth_type =content_type =content_length =

Reference documents

http://blog.csdn.net/xiaojianpitt/article/details/5785925

http://blog.csdn.net/wangfeng2500/article/details/8119959

Http://blog.sina.com.cn/s/blog_49c5f8100100ufd6.html

Apache: Add CGI Mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.