Run your own CGI program in the Nginx fastcgi way

Source: Internet
Author: User
Keywords NGINX FASTCGI CGI Program
Tags cgi program http installed it is loaded loaded into memory nginx

The biggest advantage of fastcgi is that it is highly efficient, because once the program is loaded into memory, it stays on for a long time, and does not load up on the memory for every execution, like a normal program.
Because for the large number of visits, the actual implementation of relatively simple procedures, it is best to write a fastcgi way, can significantly improve the concurrency processing capacity.

Because Nginx does not bring fastcgi tools, we need lighttpd spawn-fcgi
Older versions of the spawn-fcgi are brought in lighttpd, and new versions can be installed independently. Older versions of the system need to first

Apt Install lighttpd

Do not let lighttpd run, or modify the LIGHTTPD default port
Vi/etc/lighttpd/lighttpd.conf
Server.port = 81

What we need is:
/usr/bin/spawn-fcgi

For example, our fastcgi program is/home/www/cgi-bin/fast.bin, and he's our own CGI program written and compiled in C or other languages.
Let him reside in the background with the following command, and bind to port 10001

Spawn-fcgi-a 127.0.0.1-p 10001-u freeworm-g freeworm-f/home/www/cgi-bin/fast.bin

Edit Virtual Host, add

Location/fast.bin {
Fastcgi_pass 127.0.0.1:10001;
Include/etc/nginx/fastcgi_params;
}

You can then access it through a link like this:
Http://www.nginx.com.cn/fast.bin

Reference Document: Http://wiki.codemongers.com/NginxFcgiExample

From Nginx Chinese web: http://www.nginx.com.cn/?p=349

Related Article

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.