gpt4 book ai didi

ruby-on-rails - nginx 不在 ssl 中提供 rails Assets

转载 作者:太空宇宙 更新时间:2023-11-03 12:54:06 25 4
gpt4 key购买 nike

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

没有 ssl 一切看起来都不错,但自从我引入它后, Assets 就停止工作了。

这是我的 /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 或图像。

当我直接加载 Assets 时,我得到:

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;

需要包含公用文件夹的完整路径。可能是这样的

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

关于ruby-on-rails - nginx 不在 ssl 中提供 rails Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21734814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com