ruby-on-rails – 如何使用puma / nginx在资产管道中提供不属于/ public的资产?

这是一个AWS问题,我使用的是Ruby 2.2(Puma)平台.

我编译的资产(in / public / assets)按预期方式提供. / public中的其他资产未被送达(404).

我在哪里配置?这是一个nginx问题吗?还是美洲狮问题?

还是这只是一个AWS图像问题?

这是一个实例(robots.txt应该从根):
http://staging.us-west-2.elasticbeanstalk.com/public/robots.txt

还值得一提的是,默认的Passenger平台图像是开箱即用的.

最佳答案
如果它帮助任何人,或有人知道如何改进它,这里是nginx配置,终于得到它为我工作.在/.ebextensions/01_files.config中:

files:
    "/etc/nginx/conf.d/webapp_healthd.conf" :
        mode: "000755"
        owner: root
        group: root
        content: |
            upstream my_app {
              server unix:///var/run/puma/my_app.sock;
            }

            log_format healthd '$msec"$uri"'
                            '$status"$request_time"$upstream_response_time"'
                            '$http_x_forwarded_for';

            server {
              listen 80;
              server_name _ localhost; # need to listen to localhost for worker tier
              root /var/app/current/public;

              if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
                set $year $1;
                set $month $2;
                set $day $3;
                set $hour $4;
              }

              access_log  /var/log/nginx/access.log  main;
              access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;

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

              location @my_app {
                proxy_pass http://my_app; # match the name of upstream directive which is defined above
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              }

              location /assets {
                alias /var/app/current/public/assets;
                gzip_static on;
                gzip on;
                expires max;
                add_header Cache-Control public;
              }
            }
    "/opt/elasticbeanstalk/hooks/appdeploy/post/03_restart_nginx.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/usr/bin/env bash
            rm /etc/nginx/conf.d/webapp_healthd.conf.bak
            rm /etc/nginx/conf.d/custom.conf            
            service nginx restart

dawei

【声明】:淮南站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。