13 July 2015

error/access logging -- fedora --

/var/log/nginx/error.log

/var/log/nginx/access.log

CSS & Javascript truncated by nginx

status

  systemctl status nginx.service -l

Restart

  service nginx restart

Truncated files

/var/log/nginx/error.log

2015/02/26 01:02:51 [crit] 19369#0: *21 open() ”/var/lib/nginx/tmp/proxy/5/00/0000000005” failed (13: Permission denied) while reading upstream, client: 188.79.222.168, server: sharingkitchn.com, request: “GET /assets/application-1f612fcaf782bbd02f99bffce69383f8.js HTTP/1.1”, upstream: “http://127.0.0.1:3000/assets/application-1f612fcaf782bbd02f99bffce69383f8.js”, host: “sharingkitchn.com”, referrer: “http://sharingkitchn.com/

Solución explicada en:

Nginx – failed (13: Permission denied) while reading upstream

http://derekneely.com/2009/06/nginx-failed-13-permission-denied-while-reading-upstream/

En etc/nginx/nginx.conf

  user webs;

Situación actual:

[root@nairobi /]# ls -l /var/lib/nginx/tmp/
    total 20
    drwx------ 2 webs root 4096 ene 28 11:13 client_body
    drwx------ 9 webs root 4096 feb 11 09:14 fastcgi
    drwx------ 2 webs root 4096 ene 28 11:13 proxy
    drwx------ 2 webs root 4096 ene 28 11:13 scgi
    drwx------ 2 webs root 4096 ene 28 11:13 uwsgi

—→ correcto: propietario webs

[root@nairobi /]# ls -l /var/lib/nginx/
      total 4
      drwx------ 7 nginx nginx 4096 ene 28 11:13 tmp

—→ incorrecto: webs no tiene permisos de escritura

Solución:

  chown webs:nginx /var/lib/nginx/tmp/
<h1 class="sectionedit6" id="firewall_linux">Firewall linux</h1>
<div class="level1">

  <p>
    See the page <a href="/wikimemo/doku.php?id=linux_firewall" class="wikilink1" title="linux_firewall">linux_firewall</a>
  </p>

</div>

<h1 class="sectionedit7" id="deploy_rails_app">Deploy rails app</h1>
<div class="level1">

  <p>
    Install Nginx
  </p>
  <pre class="code">sudo apt-get install nginx</pre>

  <p>
    Create a vHost. To do this, edit <code>/etc/nginx/sites-available/myapp.example.com</code>
  </p>

  <p>
    This is a sample Nginx configuration for myapp
  </p>
  <pre class="code">upstream myapp {
    server 127.0.0.1:3000;
    server 127.0.0.1:3001;
    server 127.0.0.1:3002;
  }
  server {
  listen   80;
  server_name .example.com;

  access_log /var/www/myapp.example.com/log/access.log;
  error_log  /var/www/myapp.example.com/log/error.log;
  root     /var/www/myapp.example.com;
  index    index.html;

  location / {
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header  Host $http_host;
  proxy_redirect  off;
  try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
}

location @ruby {
proxy_pass http://myapp;   } }</pre>

And make it enabled as well:

ln -nfs /etc/nginx/sites-available/myapp.example.com /etc/nginx/sites-enabled/myapp.example.com

Switch the app Live

Restart the different daemons

/etc/init.d/thin restart
  /etc/init.d/nginx reload
  /etc/init.d/nginx restart

</div>

Let nginx serve public files directly

Add to production.rb

# send public files directly, no passing through whole rails rack
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx