Nginx不提供SSL中的Rails资产 [英] nginx not serving rails assets in ssl

查看:101
本文介绍了Nginx不提供SSL中的Rails资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在nginx(nginx版本:nginx/1.4.1(Ubuntu)),rails(Rails 3.2.16)和unicorn(unicorn v4.7.0)vps中安装自签名ssl证书.

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.

在没有ssl的情况下,一切看起来都很不错,但是自从我引入它以来,资产就停止了工作.

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

这是我的/etc/nginx/sites-enabled/[appname]配置:

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

}

当我加载页面时,我只得到纯HTML,没有CSS或图像.

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)

并在日志中:

==> 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"

有什么线索吗?

预先感谢

推荐答案

如上所述,答案是

root /public;

需要包含公用文件夹的完整路径.可能类似

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

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

这篇关于Nginx不提供SSL中的Rails资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆