Rails Rails 5 生产环境 怎么访问 public 下静态文件

ghn645568344 · October 25, 2016 · Last by msg7086 replied at October 26, 2016 · 2979 hits

RT,在 development 环境下可以访问 public 下静态文件,但是在 production 环境就访问不了,一直报路由错误。。。。。。😭 用的是 nginx + unicorn 配置的 网上查了查也没找出什么答案,nginx 用的是 root 账户

root     22110  0.0  0.0  86092  1368 ?        Ss   17:15   0:00 nginx: master process /usr/sbin/nginx
root     22111  0.3  1.0 126104 41576 ?        S    17:15   0:00 nginx: worker process
root     22112  0.3  1.0 126104 41576 ?        S    17:15   0:00 nginx: worker process
root     22114  0.3  1.0 126104 41576 ?        S    17:15   0:00 nginx: worker process
root     22115  0.3  1.0 126104 41576 ?        S    17:15   0:00 nginx: worker process
root     22118  0.0  0.0  11740   936 pts/0    S+   17:15   0:00 grep --color=auto nginx

网上查了很多,但是没找到什么有价值的。。。。请教大家了🙏

1 Floor has deleted

除了反向代理,用 nginx 做静态资源代理了吗?

config/environments/production.rb

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = true

设置为 true 启用 Rails 解析 public 目录的文件,false 关闭(默认),关闭的时候,你需要用 Nginx 实现。

#3 楼 @huacnlee 🙏 膜拜 十分感谢,谢天谢地终于出来了。。。。。😎 #2 楼 @adamshen 话说如果用 Nginx 实现的话是不是 需要转发特定的名称的这样

location /public {
        internal;
        alias $app_root/public;
}

#4 楼 @ghn645568344

root /var/www/yourapp/public/;
You need to Sign in before reply, if you don't have an account, please Sign up first.