Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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    /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;
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.