Rewrite within location with a new root/alias - Nginx -


my folder structure follows:

/www     /api.domain.tld     /app.domain.tld 

the api contains system self , app implements api via http.

i want create nginx server app.domain.tld contains "virtual directory" api.

you can contact api likes this: http://api.domain.tld/method/api.json

but great if api can contacted also: http://app.domain.tld/api/method/api.json without copying app, keep 2 "systems" separated.

what have now:

server {     listen 80;     root /var/www/app.domain.tld;     index index.php index.html;       server_name app.domain.tld;       location ^~ /api {         alias /var/www/api.domain.tld;           location ~ \.php$ {             try_files $uri = 404;             fastcgi_pass unix:/var/run/php5-fpm.sock;             fastcgi_index index.php;             fastcgi_param script_filename $document_root$fastcgi_script_name;             include fastcgi_params;         }           rewrite ^/api/([a-z]+)/api.json$ /api.php?method=$1 last;     }       location....     location....     location....       location ~ \.php$ {         try_files $uri = 404;         fastcgi_pass unix:/var/run/php5-fpm.sock;         fastcgi_index index.php;         fastcgi_param script_filename $document_root$fastcgi_script_name;         include fastcgi_params;     } } 

unfortunately works expected.

the rewrite not work @ all. can api.domain.tld/index.php when needs use rewrite, not work.

i have tried several things. either 404 or 403 error: directory index of [path] forbidden

can come better solution works?

regards

you should change script_filename path:

server {     listen 80;     root /var/www/app.domain.tld;     index index.php index.html;      location ~ ^/api/(.+\.php)$ {         alias /www/api.domain.tld/public/$1;         fastcgi_pass 127.0.0.1:9000;         fastcgi_index index.php;         fastcgi_param script_filename $request_filename;         include fastcgi_params;     }     } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -