我目前正面临着以下挑战:当我在Rails 5.2上安装乘客服务器时,我的预编译js无法加载。我试图通过rake asset:precompile来编译资产,这会将我的所有资产生成到public /文件夹中,这似乎都不错。
我将config.assets.compile更改为true,这似乎可以正常工作,但在使用带有nginx支持的乘客独立设备时,这不是好习惯。你们中的某人在使用乘客独立版时有解决方案吗?我还没有找到可行的解决方案!
Rails.application.configure do
--------------------------------SOME OTHER CONFIG--------------------------
# 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?
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(compress: { drop_console: true }) if defined?(Uglifier)
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
-----------------------------------SOME OTHER CONFIG-------------------------
end
以上是我的production.rb配置
master_process on;
daemon on;
error_log '/home/gieforce/Drieam/Eduframe/log/passenger.3000.log' ;
pid '/home/gieforce/Drieam/Eduframe/tmp/pids/passenger.3000.pid';
worker_processes 1;
events {
worker_connections 4096;
}
http {
log_format debug '[$time_local] $msec "$request" $status conn=$connection sent=$bytes_sent body_sent=$body_bytes_sent';
include '/home/gieforce/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/passenger-5.3.4/resources/mime.types';
passenger_root '/home/gieforce/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/passenger-5.3.4';
passenger_abort_on_startup_error on;
passenger_ctl pidfiles_to_delete_on_exit '["/tmp/passenger-standalone.7h2oyw/temp_dir_toucher.pid"]';
passenger_ctl integration_mode standalone;
passenger_ctl standalone_engine nginx;
passenger_user_switching off;
passenger_log_level 3;
passenger_max_pool_size 3;
### BEGIN your own configuration options ###
# This is a good place to put your own config
# options. Note that your options must not
# conflict with the ones Passenger already sets.
# Learn more at:
# https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template
### END your own configuration options ###
default_type application/octet-stream;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
client_max_body_size 1024m;
access_log off;
keepalive_timeout 60;
underscores_in_headers on;
gzip on;
gzip_vary on;
gzip_comp_level 3;
gzip_min_length 150;
gzip_proxied any;
gzip_types text/plain text/css text/json text/javascript
application/javascript application/x-javascript application/json
application/rss+xml application/vnd.ms-fontobject application/x-font-ttf
application/xml font/opentype image/svg+xml text/xml;
add_header Strict-Transport-Security "max-age=16070400; includeSubdomains";
add_header X-Frame-Options DENY;
server {
server_name _;
listen 0.0.0.0:3000;
root '/home/gieforce/Drieam/Eduframe/public';
passenger_app_root '/home/gieforce/Drieam/Eduframe';
passenger_enabled on;
passenger_app_env 'production';
passenger_spawn_method 'smart';
passenger_load_shell_envvars off;
# Rails asset pipeline & webpacker support.
location ~ "^/(assets|packs)/.+-([0-9a-f]{32}|[0-9a-f]{64}|[0-9a-f]{20})\..+" {
error_page 490 = @static_asset;
error_page 491 = @dynamic_request;
recursive_error_pages on;
if (-f $request_filename) {
return 490;
}
if (!-f $request_filename) {
return 491;
}
}
location @static_asset {
gzip_static on;
expires max;
add_header Cache-Control public;
add_header Last-Modified "";
add_header ETag "";
break;
}
location @dynamic_request {
passenger_enabled on;
}
### BEGIN your own configuration options ###
# This is a good place to put your own config
# options. Note that your options must not
# conflict with the ones Passenger already sets.
# Learn more at:
# https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template
### END your own configuration options ###
}
passenger_pre_start http://0.0.0.0:3000/;
}
上面是nginx.conf.erb,可以由乘客导入。
答案 0 :(得分:0)
您是否尝试过像rake assets:precompile RAILS_ENV=production
这样的环境或耙assets:precompile RAILS_ENV=development
这样的环境进行预编译?