simple try_files not working

Rapsey rapsey at gmail.com
Wed Feb 17 21:16:05 MSK 2010


On Wed, Feb 17, 2010 at 6:58 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Wed, Feb 17, 2010 at 06:40:30PM +0100, Rapsey wrote:
>
> > What I want is for nginx to serve a file if it can (it exists), if not to
> > proxy the request to another server.
> > I'm using 0.8.33
> >
> > server {
> >         listen 8080 default;
> >         server_name   ~^(www\.)?(?<domain>.+)$;
> >         index index.html index.htm;
> >
> >         if ($host ~* www\.(.*)) {
> >           set $host_without_www $1;
> >           rewrite ^(.*)$ http://$host_without_www$1 permanent;
> >         }
> >         location / {
> >                 root /var/www/htdocs/$domain;
> >                 try_files $uri @def;
> >         }
> >
> >         location ~ \.php$ {
> >                 proxy_set_header Host $http_host;
> >                 proxy_pass http://localhost:2000;
> >         }
> >
> >         location @def {
> >                proxy_set_header Host $http_host;
> >                proxy_pass http://localhost:9090;
> >         }
> >     }
> > }
>
> This is not going to work at all since you have an extra "}".
>
> > If I run:
> > curl -v -H "Host: domain.tv" "http://server_ip:8080/somefile"
> >
> > The request always gets sent to the server on 9090, even though
> > /var/www/htdocs/domain/somefile exists.
> > What is wrong with my config?
>
> According to your config file should be at
> /var/www/htdocs/domain.tv/somefile (note ".tv").
>
> Maxim Dounin
>
> Ahh I hate regular expressions. Thank you.
Anyone know how it would have to be formed to only take the middle part of
the domain?


Sergej
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20100217/14ae755e/attachment.html>


More information about the nginx mailing list