Is it possible with nginx?
Maxim Dounin
mdounin at mdounin.ru
Mon Feb 16 13:07:13 MSK 2009
Hello!
On Mon, Feb 16, 2009 at 12:41:44AM +0100, Peter Vage wrote:
> I have problem, can anybody know why when i use variable this code
> doesn't work, and when i type direct address it works? Strange is that
> this variable works in two other places of this config.
>
> server {
> server_name files.com *.files.com;
> ....
> ....
> if ($host ~* "(.*)\.files\.com" ) {
> set $host_without_files $1;
> }
>
> ....
> location ~* ^.+\.(jpg|jpeg|gif|png) {
> root /home/www-data/files.com/$host_without_files; ### works, folder
> web1.com created
> access_log off;
> expires 2d;
> error_page 404 = @fetch;
> break;
> }
>
> location @fetch {
> internal;
> proxy_pass http://$host_without_files; #!!!! DOESN'T WORK, 502 Bad
> Gateway, if i type here http://web1.http then it works
When you use variables in proxy_pass you have to construct full
url yourself. I.e. you should use something like
proxy_pass http://$host_without_files$request_uri;
Also note: with proxy_pass with variables nginx will be forced to
resolve backend hostname for each request. You may want to define
appropriate upstream{} blocks for servers you are mirroring to
avoid DNS resolving.
Maxim Dounin
p.s. It's probably good idea to use multiple server{}'s without using
variables. This will save some cpu.
> proxy_store on;
> proxy_store_access user:rw group:rw all:r;
> proxy_temp_path /home/www-data/temp;
> root /home/www-data/files.com/$host_without_files; ### works, folder
> web1.com created
> }
>
> Peter
>
> --
> Posted via http://www.ruby-forum.com/.
>
More information about the nginx
mailing list