2

I have trouble to set up a combination of url rewriting and fastcgi for nginx. The application server behind the fastcgi interface expects /myapp/ as base path. And I want to make this accessible under my http://myserver.com/

upstream appfcgi {
  server 127.0.0.1:6000;
  server 127.0.0.1:6001;
  server 127.0.0.1:6002;
  fair;
}


server {
  listen 80 default;
  server_name myserver.com;
  root /var/www;

  location / {
     rewrite  ^(/.*)$ /myapp$1 last;
  }

  location /myapp/ {
     include /etc/nginx/fastcgi_params;
     fastcgi_intercept_errors on;
     fastcgi_pass appfcgi;
  }

No matter what I try I always get the root path of the application server displayed. I remember I had troubles back then doing the same with apache but forgot until today I tried to do it with nginx. Any help is appreciated. thanks.

Norbert Hartl
  • 143
  • 1
  • 1
  • 6

1 Answers1

3

I don't think you need two locations here. Here's a piece of one of my configs:

        location / {
          root    /path.to.app/;
          index   index.php index.html;
          rewrite                 ^/(.*)$ /index.php?query=$1 break;
          fastcgi_pass            127.0.0.1:9000;
          fastcgi_index           index.php;
          fastcgi_param           SCRIPT_FILENAME  /path.to.app/$fastcgi_script_name;
          include                 fastcgi_params;
        }
minaev
  • 1,617
  • 1
  • 13
  • 13
  • Thanks a lot. I've managed it myself. Somehow I did not set the SCRIPT_FILENAME properly the first time. Now I'm using variables in the location handler that sets the proper prefix and that is evaluated in the fastcgi section – Norbert Hartl Apr 27 '11 at 18:00