3

I'm installing a self signed ssl certificate in my nginx (nginx version: nginx/1.4.1 (Ubuntu)), rails (Rails 3.2.16) and unicorn (unicorn v4.7.0) vps.

Everything was looking nice without ssl, but since I introduced it the assets stopped working.

here's my /etc/nginx/sites-enabled/[appname] configuration:

upstream unicorn {
  server 0.0.0.0:3000 fail_timeout=0;
}

server {
  listen [server ip]:80;
  server_name [server ip];

  location / {
    rewrite ^ https://$server_name$request_uri permanent;
  }
}

server {
  listen [server ip]:443 ssl;
  server_name [server ip];

  client_max_body_size 4G;
  keepalive_timeout 5;

  root /public;

  try_files $uri $uri/index.html $uri.html @unicorn;

  ssl_certificate      /srv/ssl/nginx.pem;
  ssl_certificate_key  /srv/ssl/nginx.key;

  ssl_session_timeout  5m;

  ssl_protocols  SSLv2 SSLv3 TLSv1;
  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers   on;


  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }


  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_intercept_errors on;

    auth_basic "Restricted";
    auth_basic_user_file /var/www/[app name]/releases/20140212165132/.htpasswd;

    proxy_pass http://unicorn;
  }

}

when I load the page, I only get the plain html, without css or images.

and when I load the assets directly I get a:

404 Not Found
nginx/1.4.1 (Ubuntu)

and in the logs:

==> nginx_error.log <==
2014/02/12 17:10:03 [error] 3307#0: *59 open() "/public/assets/logo-140-4ddb26fedaa75220d5322c85c9bd7050.png" failed (2: No such file or directory), client: [user ip], server: [server ip], request: "GET /assets/logo-140-4ddb26fedaa75220d5322c85c9bd7050.png HTTP/1.1", host: "[server ip]"

==> nginx_access.log <==
[user ip] - giulio [12/Feb/2014:17:10:03 +0000] "GET /assets/logo-140-4ddb26fedaa75220d5322c85c9bd7050.png HTTP/1.1" 404 208 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36"

any clue?

thanks in advance

1
  • 2
    I think, "root" option should contain full path to "public" directory of your application (something like "/var/www/[app name]/current/public")
    – ivalkeen
    Feb 12, 2014 at 18:00

1 Answer 1

1

The answer, as commented above, is that

root /public;

needs to contain the full path to the public folder. Possibly something like

root /home/user/apps/app_name/current/public;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.