Ruby on rails 3 未在rails应用程序的生产中加载资产
我目前运行的应用程序在ubuntu服务器上的生产环境中运行良好。但是现在我不得不配置一个Red Hat Enterprise Linux 5.5服务器来将应用部署到,我遇到了一些问题。首先是一些规格:Ruby on rails 3 未在rails应用程序的生产中加载资产,ruby-on-rails-3,deployment,nginx,capistrano,Ruby On Rails 3,Deployment,Nginx,Capistrano,我目前运行的应用程序在ubuntu服务器上的生产环境中运行良好。但是现在我不得不配置一个Red Hat Enterprise Linux 5.5服务器来将应用部署到,我遇到了一些问题。首先是一些规格: rails版本:3.2.11 ruby:1.9.3-p194 http服务器nginx+unicorn 使用rbenv管理ruby环境 部署方法:capistrano 我的nginx.conf和unicorn配置文件基于Ryan Bate的视频。因此,我设法配置了几乎所有的设备。我可以部署、连
- rails版本:3.2.11
- ruby:1.9.3-p194
- http服务器nginx+unicorn
- 使用rbenv管理ruby环境
- 部署方法:capistrano
- 已检查对父文件夹和实际资产文件的权限。他们至少对每个人都有读取权限
- 将
更改为trueconfig.assets.compile
- 遵循此处的说明,建议删除conf.d中的默认文件,并将我的自定义nginx配置文件符号链接到/etc/nginx/conf.d,而不是../sites enabled
chmod
来解决
2013/03/24 20:50:53 [error] 10851#0: *5 open() "/home/webapp/apps/my_app/current/public/assets/application-db22bc3811b126e586f5e82e794e7ee4.css" failed (13: Permission denied)
编辑3:Update/etc/nginx/nginx.conf
user nginx;
worker_processes 2;
# error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
gzip on;
include /etc/nginx/conf.d/*.conf;
# INSIDE THE /etc/ngin/conf.d/*.conf FILE #
server {
listen 80 default deferred;
# server_name example.com;
root /home/webapp/apps/my_app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
}
所以我设法解决了这个问题。部分原因在于本文的建议 对于指向所有资产文件的所有目录,我将目录权限设置为
chmod 775
。然后,对于apps/my_app/shared/assets中的所有资产(application.js等…),我授予文件此权限chmod 775
这就成功了。在我链接到的文章中,作者提到资产文件需要同时具有读取和执行权限,而不仅仅是读取权限。您知道是否必须为每次部署/预编译资产执行chmod吗?@richsinn不,您不必知道!这解决了我的问题。非常感谢。我必须把这个添加到我的dockerfile中<代码>运行chmod 755/app/public
user nginx;
worker_processes 2;
# error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
gzip on;
include /etc/nginx/conf.d/*.conf;
# INSIDE THE /etc/ngin/conf.d/*.conf FILE #
server {
listen 80 default deferred;
# server_name example.com;
root /home/webapp/apps/my_app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
}