加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

ruby-on-rails – rails – nginx puma – 静态资产不是由

发布时间:2020-12-13 21:03:25 所属栏目:Nginx 来源:网络整理
导读:我正在使用Ubuntu. 这是tutorial 我正在使用的Nginx配置: upstream my_app {server unix:///home/uname/railsproject/my_app.sock;}server {listen 88; #(I used exact 88 when I am testing now)server_name localhost; # I used exact localhost when I a

我正在使用Ubuntu.
这是tutorial

我正在使用的Nginx配置:

upstream my_app {
server unix:///home/uname/railsproject/my_app.sock;
}

server {
listen 88; #(I used exact 88 when I am testing now)
server_name localhost; # I used exact localhost when I am testing this
root /home/uname/railsproject/public; # I assume your app is located at that location

location / {
 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/ {
 # Per RFC2616 - 1 year maximum expiry
 expires 1y;
 add_header Cache-Control public;

 # Some browsers still send conditional-GET requests if there's a
 # Last-Modified header or an ETag header even if they haven't
 # reached the expiry date sent in the Expires header.
 add_header Last-Modified "";
 add_header ETag "";
 break;
 }

}

彪马命令

RAILS_ENV=production puma -e production  -b unix:///home/uname/railsproject/my_app.sock -p 8000

在地址栏中,我正在打字

http://localhost/ 

然后网站开放但静态资产不起作用.当然,我跑了

RAILS_ENV=production rake assets:precompile

和资产在公共/资产文件夹中可用
我还尝试将m.txt文件放在assets目录中并进行访问

http://localhost/assets/m.txt    

但没有奏效.我也试过这个命令:

sudo chown -R www-data:www-data public/

但这没有帮助.

最佳答案
我有类似的问题.我从irc上非常有用的#nginx频道得到了答案.他们说这是“惯用的nginx”,而另一种形式,虽然更受欢迎,但是气馁:

server {
  server_name server.com;

  # path for static files
  root /home/production/server.com/current/public;

  location / {
      try_files $uri @proxy;
      # if url path access by directory name is wanted:
      #try_files $uri $uri/ @proxy;
  }

  location @proxy {
      proxy_pass  http://localhost:9292;
      proxy_set_header Host      $host;
      proxy_set_header X-Real-IP $remote_addr;
  }
}

/ hattip:vandemar

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读