# Question about Perl CGI

**URL:** <https://www.ruby-forum.com/t/question-about-perl-cgi/205125>\
**Category:** NGINX\
**Created:** [March 30, 2011, 9:21am UTC](https://www.ruby-forum.com/t/question-about-perl-cgi/205125 "2011-03-30T09:21:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 30, 2011, 9:21am UTC](https://www.ruby-forum.com/t/question-about-perl-cgi/205125/1 "2011-03-30T09:21:40Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 30, 2011, 3:14pm UTC](https://www.ruby-forum.com/t/question-about-perl-cgi/205125/2 "2011-03-30T15:14:18Z")

</div>

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/](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](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](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 30, 2011, 5:47pm UTC](https://www.ruby-forum.com/t/question-about-perl-cgi/205125/3 "2011-03-30T17:47:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yanxin\_z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/d6d6ee/32.png) [@yanxin\_z](https://www.ruby-forum.com/u/yanxin_z)\
**Post date:** [March 30, 2011, 6:06pm UTC](https://www.ruby-forum.com/t/question-about-perl-cgi/205125/4 "2011-03-30T18:06:08Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
