How to run CGI scripts on Nginx How to run CGI scripts on Nginx nginx nginx

How to run CGI scripts on Nginx


Nginx doesn't have native CGI support (it supports fastCGI instead). The typical solution for this is to run your Perl script as a fastCGI process and edit the nginx config file to re-direct requests to the fastCGI process. This is quite a complex solution if all you want to do is run a CGI script.

Do you have to use nginx for this solution? If all you want to do is execute some Perl CGI scripts, consider using Apache or Lighttpd as they come with CGI modules which will process your CGI scripts natively and don't require the script to be run as a separate process. To do this you need install the web server and edit the web server config file to load the CGI module. For Lighttpd, you will need to add a line in the config file to enable processing of CGI files. Then put the CGI files into the cgi-bin folder.


Install another web server(Apache, Lighttpd) that runs on different port. Then proxy your CGI request to the webserver with nginx.

You just need to add this to nginx configuration, after installed a web server on 8080

location /cgi-bin {    proxy_pass http://127.0.0.1:8080;}

Take a look at Nginx Location Directive Explained for more details.


Nginx is a web server. You need to use an application server for your task, such as uWSGI for example. It can talk with nginx using its native very effective binary interface called uwsgi.