使用 rails 和 apache 进行缓存的行为出乎意料.对布局的更改在 Apache 重新启动之前不会生效



大家早上好,

在过去的两天里,我开发了我的第一个Ruby on Rails网站,我想把它部署在我的虚拟服务器上。

我认为我已经正确设置了所有内容,我可以通过我最喜欢的浏览器(火狐(请求该网站。该网站大部分是静态的,所以它有很多静态资产,我需要预编译。

但是,当我提交对自定义样式表的更改并对其进行预编译时,网络服务器(apache2 与乘客结合使用(继续提供旧的样式表/网页,这让我感到困惑,因为我认为这应该通过哈希机制来防止,它 rails 用于静态资产。

一旦我使用"service apache2 restart"重新启动 apache 服务器并通过浏览器导航到网站,我就会看到新的布局。

我怀疑这是 apache2 配置的问题,所以这是我对虚拟主机的配置(从评论中删除(:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/project/public
RailsEnv production
PassengerRuby /usr/local/rvm/wrappers/ruby-2.5.1/ruby
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /path/to/cert/file
SSLCertificateKeyFile /path/to/private/key
<FilesMatch ".(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
<Directory />
Require all denied
</Directory>
<Directory /var/www/project/public>
Options FollowSymLinks
Require all granted
</Directory>
<Location /assets/>
# Use of ETag is discouraged when Last-Modified is present                                                                                  
Header unset ETag
FileETag None
# RFC says only cache for 1 year                                                                                                            
ExpiresActive On
ExpiresDefault "access plus 1 year"
</Location>
</VirtualHost>
</IfModule>

有人有建议,我可以在哪里查找配置错误? 谢谢。

更多信息: 轨道 v5.2.1

宝石文件:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
gem 'passenger'
gem 'rails', '~> 5.2.1'
gem 'sqlite3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jquery-rails'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

由于您以production模式运行 Rails,因此您需要重新启动应用程序服务器以接收对代码的任何更改。在您的情况下,应用程序由 Apache 中的乘客模块提供服务,因此这就解释了为什么需要重新启动 Apache。

最新更新