Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

upstream appfcgi {

server {
  listen 80 default;
  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.

share|improve this question
up vote 1 down vote accepted

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

        location / {
          root    /;
          index   index.php index.html;
          rewrite                 ^/(.*)$ /index.php?query=$1 break;
          fastcgi_pass  ;
          fastcgi_index           index.php;
          fastcgi_param           SCRIPT_FILENAME  /$fastcgi_script_name;
          include                 fastcgi_params;
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.