javascript - 乘客独立不加载 JS
问题描述
我目前面临以下问题:当我使用 Rails 5.2 设置乘客服务器时,我的预编译 js 不会加载。我尝试通过 rake assets:precompile 编译资产,它将我的所有资产生成到 public/ 文件夹中,这一切似乎都很好。
我将 config.assets.compile 更改为 true,这似乎可以正常工作,但在使用带有 nginx 支持的乘客独立时,这不是一个好的做法。使用独立版Passenger时,你们中的某些人有解决方案吗?我还没有找到可行的解决方案!
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。
解决方案
您是否尝试通过这样的环境rake assets:precompile RAILS_ENV=production
或 rake对其进行预编译assets:precompile RAILS_ENV=development
?
推荐阅读
- android - android产生垃圾结果的Tensorflow推断
- c++ - 类中的 C++ 数组变量在实现文件的一个函数中导致“未在此范围内声明”错误,但在构造函数中没有
- javascript - antd 模态打开和关闭问题
- javascript - Highcharts - 多系列圆环图上的动态数据标签定位
- php - 如何在php中只打印新的数组值
- swift - 使用 NSPersistentCloudKitContainer 的可选核心数据关系问题
- protocol-buffers - 对 gRPC 消息建模的最佳方法
- ruby-on-rails - Rail6 db:migrate 失败 - 参数数量错误(给定 1,预期 0)
- sql - 为什么 select with subselect 在条件下不返回任何行的速度要慢得多?
- spring - 在spring boot中使用pageable获取和删除对象