gpt4 book ai didi

ruby-on-rails-3 - Assets 未在 Rails 应用程序的生产中加载

转载 作者:行者123 更新时间:2023-12-04 15:45:43 26 4
gpt4 key购买 nike

我正在运行的当前应用程序在其 ubuntu 服务器上的生产环境中运行良好。但是现在我不得不配置一个 Red Hat Enterprise Linux 5.5 服务器来部署应用程序,我遇到了一些问题。首先是一些规范:

  • 导轨版本:3.2.11
  • ruby :1.9.3-p194
  • http服务器nginx+ unicorn
  • 使用 rbenv
  • 管理 ruby​​ 环境
  • 部署方法:capistrano

  • 我的 nginx.conf 和 unicorn 配置文件基于 Ryan Bate 的视频。所以我设法配置了几乎所有东西。我可以部署、连接到数据库等。但是,当我访问我的应用程序页面时,所有 Assets 都无法加载。当我进入我的控制台时,它说他们因为 403 Forbidden 错误而失败。我检查了 Assets 在正确的位置:apps/my_app/shared/assets。但我不断收到这个 403 错误。

    到目前为止我已经尝试过:
  • 检查父文件夹和实际 Assets 文件的权限。他们都至少拥有每个人的读取权限
  • 已更改 config.assets.compile为真
  • 遵循此处的说明rails deployment using nginx & unicorn: 403 forbidden error ,建议删除 中的默认文件conf.d 并将我的自定义 nginx 配置文件符号链接(symbolic link)到 /etc/nginx/conf.d 而不是 .../启用站点

  • 为什么我得到 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;
    }

    }

    最佳答案

    所以我设法解决了这个问题。本文中的部分建议 http://nginxlibrary.com/403-forbidden-error/

    对于通向所有 Assets 文件的所有目录,我将目录权限设置为 chmod 775 .然后对于 中的所有 Assets (application.js 等)应用程序/my_app/shared/assets 我给了文件这个权限chmod 775 .

    这就是诀窍。在我链接到的文章中,作者提到 Assets 文件需要具有读取和执行权限,而不仅仅是读取。

    关于ruby-on-rails-3 - Assets 未在 Rails 应用程序的生产中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606312/

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