我正在运行的应用程序在其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的视频。所以我设法几乎配置了所有东西。我可以部署,连接到数据库等等。然而,当我访问我的应用程序页面时,所有资产都无法加载。当我进入控制台时,它会说它们因为403 Forbidden错误而失败了。我检查了资产是否在正确的位置:apps/my_app/shared/assets。但我仍然收到这个403错误。
到目前为止,我尝试过:
- 检查父文件夹和实际资产文件的权限。所有人都至少有读取权限
- 将
config.assets.compile
更改为true - 按照此处的说明rails deployment using nginx & unicorn: 403 forbidden error,建议删除conf.d中的默认文件,并将我的自定义nginx配置文件链接到/etc/nginx/conf.d,而不是.../sites-enabled
有什么想法或想法为什么我会得到403错误吗?
编辑1:添加/ etc / nginx / nginx.conf文件
不确定这是否有帮助,但这是nginx.conf文件(位于/ etc / nginx下)的外观(不是我的自定义nginx文件):
events {
worker_connections 1024;
}
#----------------------------------------------------------------------
# HTTP Core Module
#
# http://wiki.nginx.org/NginxHttpCoreModule
#
#----------------------------------------------------------------------
http {
include /etc/nginx/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 main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#
# The default server
#
server {
listen 80;
server_name _;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
}
另外,我注意到在/etc/nginx下有nginx.conf和nginx.conf.default文件,有人知道它们的区别吗?也许问题就出在这里了?
编辑2:添加来自nginx日志文件的条目
所以我在nginx日志文件中找到了这个。也许这是一个权限问题,可以通过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:更新/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;
}
}
RUN chmod 755 /app/public
- Srikanth Jeeva