Welcome! Log In Create A New Profile

Advanced

Re: Need help with nginx rewrites (for sub-domains)

April 28, 2011 11:22PM
On Fri, Apr 29, 2011 at 6:11 AM, Jimish Jobanputra <lists@ruby-forum.com> wrote:
> Hello,
>
> I have been scratching my head last 2 days trying to get this working:
>
> I have a Rails application, say, http://example.com and now I want to
> run a PHP app on http://example.com/coupons
>
> 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
>
> https://gist.github.com/946479
>
> Now http://example.com/coupons loads up the home page, however if I try
> http://example.com/coupons/ (with the extra slash), it says "No input
> file found"
>
> Same goes with http://example.com/coupons/Admin and so on.. somehow the
> rewrites are screwed up i guess..
>
> PS: The above code has been tweaked again and again, so if there is
> something silly, be nice and let me know ;)
>

you're thinking too far.

First, create a symlink like this:
/home/jjobanputra/code/coupon/coupons => /home/jjobanputra/code/coupon/upload

(eg.
ln -s /home/jjobanputra/code/coupon/upload /home/jjobanputra/code/coupon/coupons
)

Using alias is a shortcut for getting headache.

then the config:

#order is important.
location ~ ^/coupons/.*\.php$ {
root /home/jjobanputra/code/coupon;
try_files $uri =404;
fastcgi_pass 127.0.0.1:53217;
fastcgi_index index.php;
#probably not needed - it should be covered in fastcgi.conf
fastcgi_param SCRIPT_FILENAME $request_filename;
include /opt/nginx/conf/fastcgi.conf;
}

location /coupons/ {
root /home/jjobanputra/code/coupon;
index index.php index.html index.htm;
#this line below probably not going to work as expected
#the alternative is to capture the url using location ~ ^/coupons/(.*)
# and use it as parameter replacing uri in q=$uri
#another possible hack is using @location and rewrite.
try_files $uri $uri/ /coupons/index.php?q=$uri;
expires 30d;
}

#I find this mandatory for any kind of rewrites.
#Especially if the root is different than the global root.
#Basically a behaviour difference.
location = /coupons {
rewrite ^ /coupons/ permanent;
}

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Need help with nginx rewrites (for sub-domains)

Jimish Jobanputra April 28, 2011 07:12PM

Re: Need help with nginx rewrites (for sub-domains)

edogawaconan April 28, 2011 11:22PM

Re: Need help with nginx rewrites (for sub-domains)

Jimish Jobanputra April 29, 2011 06:02AM

Re: Need help with nginx rewrites (for sub-domains)

edogawaconan April 29, 2011 06:18AM

Re: Need help with nginx rewrites (for sub-domains)

Jimish Jobanputra April 29, 2011 06:32AM

Re: Need help with nginx rewrites (for sub-domains)

Igor Sysoev April 29, 2011 06:34AM

Re: Need help with nginx rewrites (for sub-domains)

Jimish Jobanputra April 29, 2011 06:36AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 317
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready