Question about Perl CGI

Hello,
I am trying to integrate Nginx with Perl CGI script.
I am following the How-TO
http://blog.oddeven.info/nginx-perl-fastcgi-how-to/

My conf file is conf/nginx.conf

worker_processes 1;

error_log logs/error.log notice;

working_directory /opt/nginx;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server {
    listen       80;
    client_max_body_size 100m;
    # /cgi-bin configuration

    location ~ ^/cgi-bin/.*\.cgi$ {
        gzip off;
        fastcgi_pass  unix:/var/run/nginx/perl_cgi-dispatch.sock;
        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        include fastcgi_params;
    }

}

}

I start fastcgi-wrapper.pl first, then it create perl fastcgi-wrapper.pl
in /var/run/nginx/

I put my cgi file in html/cgi_bin/print.cgi
This cgi file will print out “Hello World!!”

I start nginx, and visit 127/0.0.1/cgi_bin/print.cgi

However, the web browser can not show “Hello World!!”, instead, it will
pop a download window, to ask me to download this cgi file.

I am thinking my conf is not correct. Could you help me to solve this
issue?

Thanks,
Yanxin

On Wed, Mar 30, 2011 at 09:21:40AM +0200, Yanxin Z. wrote:

Hi there,

I am trying to integrate Nginx with Perl CGI script.
I am following the How-TO
http://blog.oddeven.info/nginx-perl-fastcgi-how-to/

    location ~ ^/cgi-bin/.*\.cgi$ {

I put my cgi file in html/cgi_bin/print.cgi
This cgi file will print out “Hello World!!”

I start nginx, and visit 127/0.0.1/cgi_bin/print.cgi

However, the web browser can not show “Hello World!!”, instead, it will
pop a download window, to ask me to download this cgi file.

You have configured to hand-to-fastcgi things below /cgi-bin.

You are requesting something below /cgi_bin. So it will be handled by
nginx, which will send you the file.

It probably sends it with Content-Type: application/octet-stream, which
a browser will frequently suggest you download.

If you try “curl -i http://127.0.0.1/cgi_bin/print.cgi
you should see the details. Then after fixing it, “curl -i
http://127.0.0.1/cgi-bin/print.cgi” should show you what you expect.

I am thinking my conf is not correct. Could you help me to solve this
issue?

  • and _ are not the same

Good luck with it,

f

Francis D. [email protected]

Hello Francis,
I understand your point of view. Thank you.
Could you tell me how to fix it?
Yanxin

On Wed, Mar 30, 2011 at 05:47:05PM +0200, Yanxin Z. wrote:

Hi there,

Could you tell me how to fix it?

location ~ ^/cgi-bin/.*.cgi$ {

I put my cgi file in html/cgi_bin/print.cgi

I start nginx, and visit 127/0.0.1/cgi_bin/print.cgi

You have “location” in nginx.conf. You have the directory your file is
in on your filesystem. You have the url you access in your web client.

Make them all use “cgi-bin”, or make them all use “cgi_bin”.

Good luck,

f

Francis D. [email protected]