1

I have a website virtual host, example.com, which is statically served out of /home/erealms/www.

However, the website runs through a series of perl scripts, which are located in various directories. So what I'm trying to accomplish is the following:

http://example.com/               -> /home/erealms/www
http://example.com/erealms        -> /home/erealms/ethereal/main
http://example.com/erealms/admin  -> /home/erealms/ethereal/mgmt/admin
http://example.com/erealms/config -> /home/erealms/ethereal/mgmt/config

In all directories except http://example.com/ there will be perl files, .pl, being served out through fcgiwrapper.

Here is my current configuration:

server {
    add_header Cache-Control public;
    access_log /var/log/nginx/access.log main buffer=32k;
    error_log /var/log/nginx/error.log error;
    expires max;
    limit_req zone=gulag burst=200 nodelay;
    listen 80;
    server_name example.com;
    index index.html index.htm default.html default.htm;
    root /home/erealms/www;

    location ~* (\.jpg|\.png|\.css)$ {
        if ($http_referer !~ ^(http://rpn.ishikawa.sne.jp) ) {
            return 405;
        }
    }
    location = /favicon.ico {
        return 204;
    }
    location /erealms/config {
        root /home/erealms/ethereal/mgmt/config/;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/config$fastcgi_script_name;
    }
    location /erealms/admin {
        root /home/erealms/ethereal/mgmt/admin/;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/admin$fastcgi_script_name;
    }
    location /erealms {
        alias /home/erealms/ethereal/main;
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:8000;
        fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/main$fastcgi_script_name;
    }
}

You'll notice that I have both root and alias directives, because I was trying to figure out what the hell was going on. Here is what's strange though. I've included below what directories are requested, and where nginx tells fcgiwrapper to access them:

http://example.com/erealms        -> /home/erealms/ethereal/main/erealms
http://example.com/erealms/admin  -> /home/erealms/ethereal/mgmt/admin/erealms/admin
http://example.com/erealms/config -> /home/erealms/ethereal/mgmt/config/erealms/config

Now for the time being, and just to get the damn thing working for further testing, I've just created lazy symlinks that point back to where they should be, but obviously this isn't a very elegant solution. If anyone could point me in the right direction to fixing this current setup to work, OR if you perhaps have an idea for a more elegant solution for this configuration, I would very much appreciate it.

Pryoidain
  • 21
  • 3
  • I've solved it, somewhat, I'll post my self answer here in a few hours once serverfault allows me too. for those wanting the quick version: location ~ /erealms/config(/.*\.pl)$ { alias /home/erealms/ethereal/mgmt/config; gzip off; include /etc/nginx/fastcgi_params; fastcgi_pass unix:/tmp/cgi.sock; fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/config/$1; } – Pryoidain Mar 05 '12 at 03:51

1 Answers1

1

Not sure how answering your own questions goes on SF, but here's what I ended up doing:

server {
    add_header      Cache-Control public;
    access_log      /var/log/nginx/access.log main buffer=32k;
    error_log       /var/log/nginx/error.log error;
    expires         max;
    limit_req       zone=gulag burst=200 nodelay;
    listen          80;
    server_name     rpn.ishikawa.sne.jp;
    root            /home/erealms/www;
    index           index.html;
    location ~* (\.jpg|\.png|\.css)$ {
            if ($http_referer !~ ^(http://rpn.ishikawa.sne.jp) ) {
                    return 405;
            }
    }
    location = /favicon.ico {
            return 204;
    }
    location ~ /erealms/config(/.*\.pl)$ {
            alias   /home/erealms/ethereal/mgmt/config;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/config/$1;
    }
    location ~ /erealms/admin(/.*\.pl)$ {
            alias   /home/erealms/ethereal/mgmt/admin;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/mgmt/admin/$1;
    }
    location ~ /erealms(/.*\.pl)$ {
            alias   /home/erealms/ethereal/main;
            gzip off;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/tmp/cgi.sock;
            fastcgi_param SCRIPT_FILENAME /home/erealms/ethereal/main/$1;
    }
}

Now unfortunately this has resulted in some other errors where I will eventually just be using an apache backend to serve the dynamic content with an nginx frontend, but I thought I would leave this here in the event someone else came across a similar problem.

Pryoidain
  • 21
  • 3