我正在我的nginx(nginx版本:nginx / 1.4.1(Ubuntu)),rails(Rails 3.2.16)和unicorn(unicorn v4.7.0)vps中安装自签名ssl证书。
没有ssl,一切都看起来不错,但是自从我介绍之后,资产就停止了工作。
这是我的/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或图像。
当我直接加载资产时,我得到一个:
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"
任何线索?
提前致谢
答案 0 :(得分:1)
如上所述,答案是
root /public;
需要包含公用文件夹的完整路径。可能类似
root /home/user/apps/app_name/current/public;