在本地环境下想要使 Rails 以 production 模式启动的话会遇到很多困难,所以总结了启动方法。
环境确认
数据库
首先,生成 production 模式所需要的 DB。
rails db:create RAILS_ENV=production
rails db:migrate RAILS_ENV=production
静态文件
在 production 模式中,静态文件由 Nginx 和 Apache 等 Web 服务器进行伺服比较合适。但是这次,由于在本地开发,Web 服务器的配置很麻烦,所以需要在 Rails 一侧伺服静态文件。
通过 Nginx 和 Apache 等 Web 服务器访问的情况下,以下内容是没有必要的。
使用编辑器打开config/environments/production.rb
后,会发现其中有这么一段
# config/environments/production.rb
config.public_file_server.enabled = E...