Rules for rewriting nginx using Passenger

I am trying to port to nginx from Apache using Passenger in both instances to host a Rails application. The application accepts the request, which is intended for the image, if the image exists in / system / logos / $ requestimage, then it must be serviced, or it must be allowed to get into the Rails application to generate it if necessary (where it is then cached to / system / logos).

In Apache, I used the following:

RewriteCond %{DOCUMENT_ROOT}/system/logos/%{REQUEST_FILENAME} -f
RewriteRule ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1

Everything went perfectly. Assets. subdomain is another subdomain, but with the same root, only a disabled Passenger, specially configured to host static files (after expiration).

In nginx, I use the following:

server {
  listen 80;
  passenger_enabled on;
  server_name  clg.eve-metrics.com www.clg.eve-metrics.com;
  root /opt/www/clg/current/public;
  gzip             on;
  gzip_min_length  1000;
  gzip_proxied     expired no-cache no-store private auth;
  gzip_types       text/plain application/xml text/css application/javascript;
  gzip_disable     msie6;
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
  }
  if (-f $document_root/system/logos$request_filename) { 
    rewrite ^/(.*)$ http://assets.clg.eve-metrics.com/system/logos/$1 break;
  }
}

. . , Rails. nginx, , , . , ?

+3
2

rails nginx . /public /public/system/cache/. , vhost:

if (-f $document_root/system/cache/$uri/index.html) {
  rewrite (.*) /system/cache/$1/index.html break;
}

if (-f $document_root/system/cache/$uri.html) {
  rewrite (.*) /system/cache/$1.html break;
}

, $request_filename, . $uri , : -)

+4

, https://gist.github.com/711913 :

  location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico)(\?[0-9]+)?$ {
      access_log off;
      expires max;
      add_header Cache-Control public;
  }

Rails , ( nginx )

0

Source: https://habr.com/ru/post/1713452/


All Articles