Configure Nginx to support CGI
I believe that the person who will read this article has a sufficient understanding of what CGI is and its role, so I will not go into details here and start configuring it directly.
It requires installation of some perl modules. I personally prefer to use perl-MCPAN-e shell.
Install FCGI
Getopt
IO
Socket
FCGI-ProcManager
IO-ALL
......
Install fcgi-0.74.tar.gz:
Tar zxvf FCGI-0.74.tar.gz
Cd FCGI-0.74
Perl Makefile. PL
Make & make install
Install the fcgi-procmanager-0.24.tar.gz package:
Tar zxvf FCGI-ProcManager-0.24.tar.gz
Cd FCGI-ProcManager-0.24
Perl Makefile. PL
Make & make install
Install the io-all-0.39.tar.gz package:
Tar zxvf IO-All-0.39.tar.gz
Cd IO-All-0.39
Perl Makefile. PL
Make & make install
Install the Nginx-fcgi script:
Mv/usr/sbin/nginx-fcgi.txt/usr/sbin/nginx-fcgi
Chmod + x/usr/sbin/nginx-fcgi
Add the following content to the Nginx configuration file:
Cat nginx. conf
Location ~ ^/Cgi-bin/. * \. cgi $
{
Root/work/www/test;
Fastcgi_index index. cgi;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include nginx_fcgi_params;
Fastcgi_read_timeout 5 m;
Fastcgi_pass unix:/var/run/nginx-fcgi.sock;
}
Nginx-fcgi-l/var/log/nginx/nginx-fcgi.log-pid/var/run/nginx-fcgi.pid-S/var/run/nginx-fcgi.sock
Startup error:
Can't open file '/var/log/nginx/nginx-fcgi.log' for append:
There is no such file or directory at/usr/local/nginx/sbin/nginx-fcgi line 43
Solution:
Mkdir-p/var/log/nginx
Chown nobody: nobody/var/log/nginx
Start again, OK
Chown nginx. nginx/var/run/nginx-fcgi.sock
Chmod 755/var/run/nginx-fcgi.sock
Restart nginx
Create nginx-fcgi script command configuration and copy the template directly from fastcgi_params. Some documents on the Internet said that the template was copied from/etc/nginx/fastcgi_params. This document was not found at this location during deployment, there is no/etc/nginx folder. It may be because the version is different from the Nginx installation method. I created this folder, and found the script command file/usr/local/nginx/conf/fastcgi_params.default:
Cp/usr/local/nginx/conf/fastcgi_params.default/etc/nginx/nginx_fcgi_params
The work has actually been completed here, but my current company needs to be able to display mathematical formulas on the webpage. Therefore, the following two steps are to add a mimetex. cgi (which can be downloaded online) files to/web/www/cgi-bin (if this directory is not available, manually create it, with this file system, you can convert the "text format formula" submitted by the user to "True formula"
Mkdir/etc/nginx
Cd/web/www/cgi-bin/
Chmod + x mimetex. cgi
Recommended reading:
Configure and optimize reverse proxy and load balancing in Nginx
Nginx load balancing: nginx: [emerg] cocould not build the types_hash
Nginx Load Balancing module ngx_http_upstream_module details
Nginx + Firebug allows the browser to tell you which Server Load balancer distributes requests
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)
Nginx details: click here
Nginx: click here