How to enable CGI in nginx

Source: Internet
Author: User
Tags socket zip


Note: to use the Tcl script in nginx, the configuration process is recorded here and has been tested to be valid.

Install fcgiwrap

Fcgi-devel is required to install fcgiwrap. This package is included in epel and can be directly installed If epel is already installed.

Yum install fcgi-devel
Download and install fcgiwrap

Wget https://github.com/gnosek/fcgiwrap/archive/master.zip-O fcgiwrap.zip
Unzip fcgiwrap.zip
Fccd giwrap-master
Autoreconf-I # if an error is reported, install the automake package.
./Configure
Make
Make install
Install spawn-fcgi

Install the spawn-fcgi package to run fcgiwrap as a daemon.

Yum install spawn-fcgi
Edit the spawn-fcgi configuration file

Vi/etc/sysconfig/spawn-fcgi
Add the following content:

FCGI_SOCKET =/var/run/fcgiwrap. socket
FCGI_PROGRAM =/usr/local/sbin/fcgiwrap
FCGI_USER = nginx
FCGI_GROUP = nginx
FCGI_EXTRA_OPTIONS = "-M 0700"
OPTIONS = "-u $ FCGI_USER-g $ FCGI_GROUP-s $ FCGI_SOCKET-S $ FCGI_EXTRA_OPTIONS-F 1-P/var/run/spawn-fcgi.pid -- $ FCGI_PROGRAM"
NOTICE:-F 1 indicates to start a fcgiwrap process. If you have performance requirements, you can start several more
Add boot start:

Chkconfig spawn-fcgi on
Start the spawn-fcgi service:

Service spawn-fcgi start
Set nginx

Add the following configuration in nginx. conf:

Location/cgi-bin /{
Gzip off;
Root/var/www /;
Fastcgi_pass unix:/var/run/fcgiwrap. socket;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fast
Cgi_script_name;

        }
Create the/var/www/cgi-bin directory

Mkdir/var/www/cgi-bin
Grant nginx directory permissions

Chown-R nginx: nginx/var/www/cgi-bin
Create a test. cgi test file in the/var/www/cgi-bin directory.

#! /Usr/bin/tclsh

Puts "Content-type: text/html"
Puts ""
Puts "This is a tcl test script"
Modify the file permission so that it has the execution permission

Chmod 755 test. cgi
Open your browser and you will be able to see the script execution content.


Http: // localhost/cgi-bin/test. cgi


By now, the Tcl script can be executed in CGI mode, and the playability of the Tcl script is stronger. You can also execute bash, python, and other script languages in this way.

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.