首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >独立客运站不装载JS

独立客运站不装载JS
EN

Stack Overflow用户
提问于 2018-09-24 23:50:21
回答 1查看 87关注 0票数 1

我现在面临的问题是:当我在Rails 5.2上设置一个乘客服务器时,我的预编译的js无法加载。我尝试通过rake seem :precompile来编译资源,这会将我所有的资源生成到public/文件夹中,这看起来都很好。

我把config.assets.compile改成了true,这似乎是可行的,但在使用支持nginx的passenger standalone时,这并不是一个好的做法。有没有人在使用Passenger单机版的时候有解决方案?我还没有找到一个可行的解决方案!

代码语言:javascript
运行
复制
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配置

代码语言:javascript
运行
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2018-09-25 03:09:30

你有没有尝试过通过像这样的rake assets:precompile RAILS_ENV=production或者rake assets:precompile RAILS_ENV=development这样的环境来预编译?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52483017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档