Nginx - Rewrites help.
I have been scratching my head last 2 days trying to get this working:
I have a Rails application, say,
I set up the PHP app but I am having a hard time with nginx rewrites. I hope someone here can assist me:
Here's how I set up things in nginx.conf
location /coupons/ {
alias /home/jjobanputra/code/coupon/upload/;
index index.php index.html index.htm;
if (-e $request_filename) {
expires 30d;
break;
}
rewrite /coupons/(.+)$ /coupons/index.php?q=$1;
}
location = /coupons {
try_files $uri $uri/ @coupons;
}
location @coupons {
include fastcgi_params;
fastcgi_pass 127.0.0.1:53217;
fastcgi_split_path_info ^(/coupons)(/.*)$;
fastcgi_param SCRIPT_FILENAME /home/jjobanputra/code/coupon/upload/index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /coupons/?.*\.php$ {
if ($fastcgi_script_name ~ /coupons/?(.*)$) {
set $valid_fastcgi_script_name /$1;
}
fastcgi_pass 127.0.0.1:53217;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/jjobanputra/code/coupon/upload/$valid_fastcgi_script_name;
include /opt/nginx/conf/fastcgi.conf;
}
Now
Same goes with
PS: The above code has been tweaked again and again, so if there is something silly, be nice and let me know
1 Reply
Could you describe what types of files you're serving from the /coupon? How many .php scripts? Are you looking to list directories? Are there actually any index.html files or should everything that isn't an existing static file be passed to index.php?