Nginx : Use CGI Scripts2023/07/04 |
Configure CGI executable Environment on Nginx.
|
|
[1] | Install FastCGI Wrap and Configure Nginx for it. |
root@www:~#
apt -y install fcgiwrap
root@www:~#
vi /etc/nginx/fcgiwrap.conf # create new # for example, enable CGI under [/cgi-bin] location /cgi-bin/ { gzip off; root /var/www; fastcgi_pass unix:/var/run/fcgiwrap.socket; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } # add settings into [server] section of a site definition root@www:~# vi /etc/nginx/sites-available/default
server {
.....
.....
include fcgiwrap.conf;
}
root@www:~# systemctl enable --now fcgiwrap root@www:~# systemctl reload nginx |
[2] | Create a test scripts with a language (example below is Python3) under the directory you set CGI executable ([/usr/share/nginx/cgi-bin] on this example) and Access to it to verify CGI works normally. |
root@www:~#
vi /var/www/cgi-bin/index.cgi #!/usr/bin/python3 print("Content-type: text/html\n") print("<html>\n<body>") print("<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">") print("CGI Script Test Page") print("</div>") print("</body>\n</html>") chmod 705 /var/www/cgi-bin/index.cgi |
Sponsored Link |