Apache 不提供资产 - Rails 5、Puma、Apache、Windows Server 2012 R2



我无法让 css 和 js 使用 Apache 渲染我的运行 Puma的 Rails 5 应用程序。我见过关于这个问题的类似问题,但没有一个对我有用,所以我认为它可能特定于这个堆栈,或者因为我在我的 httpd-vhosts.conf 文件中缺少有关位置匹配的内容。这是我所拥有的:

<VirtualHost *:80>
ServerName clientdb
DocumentRoot "C:/Bitnami/rubystack-2.2.7-0/projects/clientdb/public/"
<Directory "C:/Bitnami/rubystack-2.2.7-0/projects/clientdb/public/" >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
<Proxy balancer://puma_cluster>
BalancerMember http://127.0.0.1:3003
BalancerMember http://127.0.0.1:3004
</Proxy>
ProxyPass /favicon.ico !
ProxyPass /robots.txt !
ProxyPassMatch ^/(404|422|500).html$ !
ProxyPass /assets/ !
ProxyPass / balancer://puma_cluster/
# enumerate all nodes for proxypassreverse since it adds a trailing slash :( bugid 51982
ProxyPassReverse / http://127.0.0.1:3003
ProxyPassReverse / http://127.0.0.1:3004
# ProxyPass / balancer://puma_cluster/ lbmethod=byrequests
# ProxyPass / balancer://puma_cluster/ lbmethod=bytraffic
# ProxyPass / balancer://puma_cluster/ lbmethod=bybusyness
<FilesMatch .css.gz$>
ForceType text/css
Header set Content-Encoding gzip
</FilesMatch>
<FilesMatch .js.gz$>
ForceType text/javascript
Header set Content-Encoding gzip
</FilesMatch>
<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>

<LocationMatch "^/assets/.*.(css|js)$">
RewriteEngine on
# Make sure the browser supports gzip encoding before we send it,
# and that we have a precompiled .gz version.
RewriteCond %{HTTP:Accept-Encoding} b(x-)?gzipb
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+)$ $1.gz
</LocationMatch>
# Make sure Content-Type is set for 'real' type, not gzip,
# and Content-Encoding is there to tell browser it needs to
# unzip to get real type.
# Make sure Vary header is set; while apache docs suggest it
# ought to be set automatically by our RewriteCond that uses an HTTP
# header, does not seem to be reliably working.
<LocationMatch "^/assets/.*.css.gz$">
ForceType text/css
Header set Content-Encoding gzip
Header add Vary Accept-Encoding
</LocationMatch>
<LocationMatch "^/assets/.*.js.gz$">
ForceType application/javascript
Header set Content-Encoding gzip
Header add Vary Accept-Encoding
</LocationMatch>

这是config/environment/production.rb。(我已经尝试启用和禁用静态文件服务器,但都不起作用)

Rails.application.configure do
# Settings specified here will take precedence over those in 
config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
config.threadsafe!
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true
# Disable serving static files from the `/public` folder by default 
since
# Apache or NGINX already handles this.
# config.public_file_server.enabled = 
ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = false
# config.public_file_server.enabled = true
# Compress JavaScripts and CSS.
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# config.assets.prefix = '/clientdb/public/assets'
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# added by KO to try fix for serving assets on apache
# config.assets.digest = true
# config.assets.debug = true
# Enable serving of images, stylesheets, and JavaScripts from an asset 
server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache

我在这里错过了什么?我能够使用 CDN 进行引导渲染,但其余部分仍然缺失,理想情况下,我想保持我的资产管线完好无损。如果我必须使用 CDN,那就这样吧,但我觉得这可能只是一个调整。

您需要在 ProxyPassReverse 语句的末尾加一个"/"。

这里提出了一个类似的问题:https://stackoverflow.com/a/9929360/4038302

最新更新