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 {
  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.

1 Answer 1


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  ;
          fastcgi_index           index.php;
          fastcgi_param           SCRIPT_FILENAME  /path.to.app/$fastcgi_script_name;
          include                 fastcgi_params;
  • 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 Apr 27, 2011 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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