ruby on rails 与 nginx 配置文件

ruby on rails 与 nginx 配置文件

我正在尝试让 nginx 上传模块与我的应用程序一起工作。我修改了 nginx.conf 文件中的服务器块,当我尝试访问我的网站时,这样做会引发 403 Forbidden 错误。日志显示无法访问 rails 公共目录。

http {
passenger_root /opt/passenger-3.0.0;
passenger_ruby /usr/bin/ruby1.8;

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


sendfile        on;
#tcp_nopush     on;
client_max_body_size 30M; #allow large uploads
#keepalive_timeout  0;


#gzip  on;

server {
    listen       80;
    server_name  url.com;
    root /path/current/public;


 # Match this location for the upload module
 location /images/fast_upload {
 # pass request body to here
 upload_pass @fast_upload_endpoint;


 upload_store /path/shared/uploads_tmp 1;

 # set permissions on the uploaded files
  upload_store_access user:rw group:rw all:r;

 # Set specified fields in request body
 # this puts the original filename, new path+filename and content type in the$
 upload_set_form_field upload[fast_asset][original_name] "$upload_file_name";
 upload_set_form_field upload[fast_asset][content_type] "$upload_content_type$
 upload_set_form_field upload[fast_asset][filepath] "$upload_tmp_path";

 upload_pass_form_field "^image_id$|^authenticity_token$|^format$";
 upload_cleanup 400 404 499 500-505;
 }

 location @fast_upload_endpoint {


  passenger_enabled on;
  rails_env production;
 }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

  }
 }

当我将“passenger_enabled on”移出位置块时,它工作正常。但是,nginx 似乎不会使用 .conf 文件中的配置进行文件上传。

答案1

location @fast_upload_endpoint {

     passenger_enabled on;
     rails_env production;
  }
location / {
 rails_env production;
 passenger_enabled on;
}

我添加了第二个位置块,现在看来没问题了。

相关内容