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

前端之家收集整理的这篇文章主要介绍了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中:
  1. files:
  2. "/etc/Nginx/conf.d/webapp_healthd.conf" :
  3. mode: "000755"
  4. owner: root
  5. group: root
  6. content: |
  7. upstream my_app {
  8. server unix:///var/run/puma/my_app.sock;
  9. }
  10.  
  11. log_format healthd '$msec"$uri"'
  12. '$status"$request_time"$upstream_response_time"'
  13. '$http_x_forwarded_for';
  14.  
  15. server {
  16. listen 80;
  17. server_name _ localhost; # need to listen to localhost for worker tier
  18. root /var/app/current/public;
  19.  
  20. if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
  21. set $year $1;
  22. set $month $2;
  23. set $day $3;
  24. set $hour $4;
  25. }
  26.  
  27. access_log /var/log/Nginx/access.log main;
  28. access_log /var/log/Nginx/healthd/application.log.$year-$month-$day-$hour healthd;
  29.  
  30. try_files $uri/index.html $uri @my_app;
  31.  
  32. location @my_app {
  33. proxy_pass http://my_app; # match the name of upstream directive which is defined above
  34. proxy_set_header Host $host;
  35. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  36. }
  37.  
  38. location /assets {
  39. alias /var/app/current/public/assets;
  40. gzip_static on;
  41. gzip on;
  42. expires max;
  43. add_header Cache-Control public;
  44. }
  45. }
  46. "/opt/elasticbeanstalk/hooks/appdeploy/post/03_restart_Nginx.sh":
  47. mode: "000755"
  48. owner: root
  49. group: root
  50. content: |
  51. #!/usr/bin/env bash
  52. rm /etc/Nginx/conf.d/webapp_healthd.conf.bak
  53. rm /etc/Nginx/conf.d/custom.conf
  54. service Nginx restart

猜你在找的Ruby相关文章