Forum: NGINX Is it possible with nginx?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-15 22:05
I would like to delegate dedicated server for hosting static files for
some of my websites. For example i have got domains web1.com, web2.com
and web34.com on first server. On second server I have got domain
files.com.

I would like to ask you if this possible that i make links on web 1,2,3
which looks like:
http://web1.com.files.com/path/image.jpg
http://web2.com.files.com/path/path/file.zip
http://web3.com.files.com/another-path/background.gif

browsers try to get files from this links but there aren't this files,
so on second server there is script index.php which download files from
right servers and create folders /web1.com/path/image.jpg ,
/web2.com/path/path/file.zip etc and send to browser this files. When
another browser want that files then there are just that files on
files.com server.

I don't know how to setu nginx config on second server that
http://web1.com.files.com/path/image.jpg
was
http://web1.com.files.com/web1.com/path/image.jpg

This kind of solution is used by Coral CDN
http://wiki.coralcdn.org/wiki.php?n=Main.FAQ

Have you got any solution how to do this?
Maybe have you got any other idea how to create backup and speed up web
server at the same time?

Best regards
Peter
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-02-15 22:56
(Received via mailing list)
Hello!

On Sun, Feb 15, 2009 at 10:05:31PM +0100, Peter Vage wrote:

>
> http://web1.com.files.com/web1.com/path/image.jpg
>
> This kind of solution is used by Coral CDN
> http://wiki.coralcdn.org/wiki.php?n=Main.FAQ
>
> Have you got any solution how to do this?
> Maybe have you got any other idea how to create backup and speed up web
> server at the same time?

http://wiki.codemongers.com/NginxHttpProxyModule#proxy_store

Just create appropriate server's for web1.com.files.com etc, and
proxy_pass on 404 to the original server with proxy_store enabled.

Maxim Dounin
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-15 23:07
Maxim Dounin wrote:
>> http://web1.com.files.com/web1.com/path/image.jpg
>>
>> This kind of solution is used by Coral CDN
>> http://wiki.coralcdn.org/wiki.php?n=Main.FAQ
>>
>> Have you got any solution how to do this?
>> Maybe have you got any other idea how to create backup and speed up web
>> server at the same time?
>
> http://wiki.codemongers.com/NginxHttpProxyModule#proxy_store
>
> Just create appropriate server's for web1.com.files.com etc, and
> proxy_pass on 404 to the original server with proxy_store enabled.
>
> Maxim Dounin

Can I use one server to cache files for example 10 domains? or should i
create one server for one domain? I am playing with nginx from two days,
it is amazing server, but very differnet from apache.

Peter
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-16 00:41
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
  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
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-16 10:06
(Received via mailing list)
On Mon, Feb 16, 2009 at 12:41:44AM +0100, Peter Vage wrote:

>   }
>
>   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

-   proxy_pass http://$host_without_files;
+   proxy_pass http://$host_without_files.http;
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-16 10:33
Igor Sysoev wrote:
>>   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
>
> -   proxy_pass http://$host_without_files;
> +   proxy_pass http://$host_without_files.http;

I am very sorry, i did mistake, was very late.

in my config in proxy_pass was web1.com not web1.http

proxy_pass http://$host_without_files; #!!!! DOESN'T WORK, 502 Bad
Gateway, if i type here http://web1.com then it works

This is my all config which make 502 Bad Gateway

server {
listen   80;
  server_name files.com *.files.com;
  access_log off;
  error_log off;

  if ($host ~* "(.*)\.files\.com" ) {
  set $host_without_files $1;
  }

        location ~* ^.+\.(jpg|jpeg|gif|png) {
    root /home/www-data/files.com/$host_without_files;
    access_log off;
    expires 1d;
    error_page 404 = @fetch;
    break;
        }

        location @fetch {
    internal;
    proxy_pass http://$host_without_files;
    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;
        }

        location / {
    root   /home/www-data/files.com;
    index  index.html index.htm;
        }
    }
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-02-16 11:19
(Received via mailing list)
Hello!

On Mon, Feb 16, 2009 at 12:41:44AM +0100, Peter Vage wrote:

>   }
>
>   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.
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-16 12:04
Maxim Dounin wrote:
>
> 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 this way isn't work too, but you have right, better to create
multiple server{}, then i have control, that i can cache only what i
want, and as you told save cpu.

Thank you.

Peter

>
> p.s. It's probably good idea to use multiple server{}'s without using
> variables.  This will save some cpu.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-02-16 12:43
(Received via mailing list)
On Mon, Feb 16, 2009 at 10:33:07AM +0100, Peter Vage wrote:

>
> in my config in proxy_pass was web1.com not web1.http
>
> proxy_pass http://$host_without_files; #!!!! DOESN'T WORK, 502 Bad
> Gateway, if i type here http://web1.com then it works

Have you tried

   proxy_pass http://$host_without_files.com$request_uri;

?
3317067acf130e7107d82ce65675afd2?d=identicon&s=25 Peter Vage (servage)
on 2009-02-16 12:59
Igor Sysoev wrote:
> On Mon, Feb 16, 2009 at 10:33:07AM +0100, Peter Vage wrote:
>
>>
>> in my config in proxy_pass was web1.com not web1.http
>>
>> proxy_pass http://$host_without_files; #!!!! DOESN'T WORK, 502 Bad
>> Gateway, if i type here http://web1.com then it works
>
> Have you tried
>
>    proxy_pass http://$host_without_files.com$request_uri;
>
> ?

Yes I have website http://web1.com/image.jpg
I go to http://web1.com.files.com/image.jpg

I am using
  if ($host ~* "(.*)\.files\.com" ) {
  set $host_without_files $1;
  }

proxy_pass http://web1.com; #works, cache file is under
/web1.com/image.jpg
proxy_pass http://host_without_files; # not work, 502 Bad Gateway
proxy_pass http://host_without_files$request_uri; # not work, 502 Bad
Gateway
proxy_pass http://host_without_files.com$request_uri; # not work, 502
Bad Gateway, why .com is before $request_uri

I would be better when it catch any websites before files.com, but then
i can't control who use it, and as said Maxim it could use more cpu.

I did as say Maxim, but it is question why it don't work, I am using
0.7.24, i see that Coral Content Delivery Network use the same version.
They response header is:

Server: nginx/0.7.24
Date: Mon, 16 Feb 2009 12:59:27 GMT
Content-Type: image/jpeg
Content-Length: 66965
Last-Modified: Mon, 09 Feb 2009 18:14:52 GMT
Connection: close
Accept-Ranges: none
Via: HTTP/1.0 193.63.75.21:8080 (CoralWebPrx/0.1.19 (See
http://coralcdn.org/))
Cache-Control: max-age=2595698
Expires: Wed, 18 Mar 2009 12:59:27 GMT

200 OK

Regards,
Peter
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-02-16 14:09
(Received via mailing list)
Hello!

On Mon, Feb 16, 2009 at 12:59:34PM +0100, Peter Vage wrote:

> >
>   }
>
> proxy_pass http://web1.com; #works, cache file is under
> /web1.com/image.jpg
> proxy_pass http://host_without_files; # not work, 502 Bad Gateway
> proxy_pass http://host_without_files$request_uri; # not work, 502 Bad
> Gateway
> proxy_pass http://host_without_files.com$request_uri; # not work, 502
> Bad Gateway, why .com is before $request_uri

At least, you forgot '$' before host_without_files here.

> I would be better when it catch any websites before files.com, but then
> i can't control who use it, and as said Maxim it could use more cpu.
>
> I did as say Maxim, but it is question why it don't work, I am using
> 0.7.24, i see that Coral Content Delivery Network use the same version.

0.7.24 is a bit old, but it should work regardless.

Probably you have no resolver defined (and no matching upstream{}
blocks).  Try looking into error_log, it has something for you.
If it doesn't help - try tcpdump to find out what's happending on
the wire.

Maxim Dounin
This topic is locked and can not be replied to.