I achieve to make multiples version of micro phalcon APIs on nginx :
Here my projects on file system :
- /var/www/myapp
- /1.0
phalcon project
- /1.1
phalcon project
- /404.html
And my nginx configuration file :
server {
listen 80;
server_name api.my-domain.com;
error_log /var/log/myapp/api/error.log;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
root /var/www/myapp/;
## 404 PAGE FOR FACTCGI ERRORS
error_page 404 /404.html;
## OTHER RULES (GZIP...)
location @rewrite {
rewrite ^(/1.0|/1.1|)/(.*)$ $1/public/index.php?_url=/$2;
}
## EXAMPLE OF REWRITE :
##
## URL INPUT
## https://api.my-domain.com/1.1/test
##
## URL OUTPUT
## https://api.my-domain.com/1.1/public/index.php?_url=/test
location ~/1.0.*\.php$ {
root /var/www/myapp/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index /index.php;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~/1.1.*\.php$ {
root /var/www/myapp/;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
##CATCH URLs WITHOUT VERSIONS -- SET VERSION 1.1 BY DEFAULT
location ~ \.php$ {
root /var/www/myapp/1.1/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index /index.php;
fastcgi_intercept_errors on;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
## WARN : MAKE SUR TO HAVE SAME FILES IN 1.0 & 1.1 PUBLIC FOLDERS (NOT A PROBLEM FOR APIs)
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root /var/www/myapp/1.1/public;
}
location ~ /\.ht {
deny all;
}
}
Now you juste have to call https://api.my-domain.com/{version}/{yourlocation} and nginx will redirect to the {version}/public/index.php.
Hope it may help someone.