Ứng dụng hiện tại tôi đang chạy đang hoạt động tốt trong quá trình sản xuất trên máy chủ ubuntu. Nhưng bây giờ tôi đã phải cấu hình một máy chủ Red Hat Enterprise Linux 5.5 để triển khai ứng dụng và tôi đang gặp một số vấn đề. Trước hết một số thông số kỹ thuật:Tài sản không tải trong sản xuất cho ứng dụng đường ray
- ray phiên bản: 3.2.11
- ruby: 1.9.3-p194
- http máy chủ nginx + lân
- quản lý môi trường ruby với rbenv phương pháp
- triển khai: capistrano
Tệp cấu hình nginx.conf và unicorn dựa trên video của Ryan Bate. Vì vậy, tôi quản lý để có được gần như tất cả mọi thứ cấu hình. Tôi có thể triển khai, kết nối với cơ sở dữ liệu, v.v. Tuy nhiên, khi tôi truy cập trang của ứng dụng, tất cả nội dung không tải được. Và khi tôi đi vào bàn điều khiển của tôi nó nói rằng họ đã thất bại vì một lỗi 403 bị cấm. Tôi đã kiểm tra và nội dung ở đúng vị trí: apps/my_app/shared/assets. Nhưng tôi tiếp tục nhận được lỗi này 403.
Những gì tôi đã cố gắng cho đến nay:
- kiểm tra quyền truy cập vào các thư mục phụ huynh và các tập tin tài sản bị mất. Tất cả họ đều đã ít nhất đọc quyền cho tất cả mọi người
- thay đổi
config.assets.compile
true - hướng dẫn Tiếp theo đây rails deployment using nginx & unicorn: 403 forbidden error, mà đề nghị loại bỏ các tập tin mặc định trong conf.d và symlinking tập tin cấu hình nginx tùy chỉnh của tôi để /etc/nginx/conf.d như trái ngược với .../sites-enabled
Bất kỳ suy nghĩ hay ý tưởng tại sao tôi nhận được một 403?
Sửa 1: thêm tập tin /etc/nginx/nginx.conf
Không chắc chắn nếu điều này giúp nhưng đây là những gì các tập tin nginx.conf (dưới/etc/nginx) trông giống như (không phải tùy chỉnh của tôi tập tin 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;
}
Ngoài ra, tôi nhận thấy rằng dưới /etc/nginx có file nginx.conf và nginx.conf.default, không ai biết sự khác biệt? Có lẽ vấn đề có thể ở đó?
Chỉnh sửa 2: Thêm vào từ file nginx log
Vì vậy, tôi thấy điều này trong file nginx log. Vì vậy, có thể đó là vấn đề về quyền có thể được sửa với 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)
Sửa 3: Cập nhật /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;
}
}
bạn có biết mình có phải thực hiện chmod cho mỗi lần triển khai/biên dịch tài sản không? – richsinn
@richsinn Không, bạn không cần phải – Alfie