Rails5资产未加载:NGINX,Unicorn,13:权限被拒绝或2:文件丢失

时间:2018-05-26 06:57:02

标签: nginx ruby-on-rails-5

我在Unicorn和NGINX上有一个Rails5应用程序,它不提供js和css。错误是:

(13: Permission denied), client: IP, server: DOMAIN, request: "GET /assets/application.self-49845c4836a1476d214788cff889c08d33fa1db30f8989214d2d7f81ef885e67.js?body=1 HTTP/1.1", host: IP, referrer: IP

所以我按照here的说法将NGINX用户更改为root并获取新的错误消息:

"/root/app_name/public/assets/gmaps/objects/base_builder.self-2a2088185a25893bbee6bf3da7fde2f1160e33f9903e29e01701ecdf87326e98.js" failed (2: No such file or directory), client: IP, server: DOMAIN, request: "GET /assets/gmaps/objects/base_builder.self-2a2088185a25893bbee6bf3da7fde2f1160e33f9903e29e01701ecdf87326e98.js?body=1 HTTP/1.1", host: DOMAIN

这是我的nginx.config:

user www-data;
# user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
  worker_connections 1024;
}

http {

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE;
  ssl_prefer_server_ciphers on;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;

  gzip on;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

这是我的网站启用/域名文件

upstream app_name {
  server unix:/tmp/unicorn.sock fail_timeout=0;
}


server {
  listen 80 default deferred;
  server_name DOMAIN

  root /root/app_name/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @app_name;

  location @app_name {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_pass http://app_name;

  }

  error_page 500 502 503 504 /500.html;

  client_max_body_size 4G;
  keepalive_timeout 10;
}

只有没有NGINX的应用程序才适用于Unicorn

0 个答案:

没有答案