在服务器中预编译的资产,但在puma和nginx服务器中未显示

jmp7cifd  于 2022-11-02  发布在  Nginx
关注(0)|答案(2)|浏览(191)

我使用Capistrano和puma以及ngnix成功地部署了rails应用程序。部署后,服务器中没有加载资产。我可以使用以下命令在服务器中进行资产预编译:RAILS_ENV=生产捆绑包执行rake资产:预编译和本地都可以。我可以在公用文件夹中看到预编译资产。在本地,它工作正常。但它没有在服务器中加载资产。我无法修复它。
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

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local = true
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like
  # NGINX, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

# config.serve_static_assets =true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true
 # config.assets.precompile += ['omnisling.scss']

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  #config.active_record.dump_schema_after_migration = false

  #
  # Created new env variable in server .bashrc file as ENV["EMAIL_HOST"] to hold the domain name
  # And Changed below line with new env variable, ref: https://omnisling.atlassian.net/browse/OMNS-54
  # Changed By: Aravind Sankar
  # Date : 25 June 2018

  config.action_mailer.default_url_options = {:host => ENV["EMAIL_HOST"]}

  config.after_initialize do
    ActiveMerchant::Billing::Base.mode = :test
    # ::GATEWAY = ActiveMerchant::Billing::JetpayGateway.new(
    #     # :login     => 'TESTMCC3016X',
    #     :login     => 'AO03B5GME9ZK',
    #     version:    {subscriber: 'BOZHZU', dll: 'GreenBasket 1.0'}
    # )

    # paypal_options = {
    #   login: ENV['PAYPAL_LOGIN'],
    #   password: ENV['PAYPAL_PASSWORD'],
    #   signature: ENV['PAYPAL_SECRET']
    # }
    # ::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)

    # spreedly_options = {
    #   login:  ENV['SPREEDLY_ENV_KEY'],
    #   password: ENV['SPREEDLY_ACCESS_SECRET'],
    #   gateway_token: ENV['SPREEDLY_GATEWAY_KEY']
    # }
    # ::SPREEDLY_GATEWAY = ActiveMerchant::Billing::SpreedlyCoreGateway.new(spreedly_options)
  end

  # Paperclip::Attachment.default_options.merge!({
  #   :storage => :s3,
  #   :bucket => ENV["S3_BUCKET"],
  #   :path           => ':class/:id/:style.:extension',
  #   :s3_credentials => {
  #     :access_key_id => ENV["S3_SECRET"],
  #     :secret_access_key => ENV["S3_ACCESS_KEY"]
  #   },
  #   :s3_protocol => :https,
  #   :s3_headers => { 'Cache-Control' => 'max-age=315576000', 'Expires' => 10.years.from_now.httpdate }
  # })

  config.paperclip_defaults = {
      :storage => :s3,
      :s3_credentials => {
          :bucket => ENV['S3_BUCKET_NAME'],
          :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
          :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
      },
      :url => ':s3_domain_url',
      :path => '/:class/:attachment/:id_partition/:style/:filename'
  }

  # Commented to test AWS SES. Below is for Sendgrid.
  # config.action_mailer.smtp_settings = {
  #  :address              => ENV['SMTP_ADDRESS'],
  #  :port                 => ENV['SMTP_PORT'],
  #  :user_name            => ENV['SMTP_USERNAME'],
  #  :password             => ENV['SMTP_PASSWORD'],
  #  :authentication       => 'plain',
  #  :enable_starttls_auto => true
  # }

  # For AWS SES
  config.action_mailer.smtp_settings = {
      :address => ENV['SES_SMTP_ADDRESS'],
      :port => ENV['SES_SMTP_PORT'],
      :user_name => ENV['SES_SMTP_USERNAME'],
      :password => ENV['SES_SMTP_PASSWORD'],
      :authentication => :login,
      :enable_starttls_auto => true
  }
  Paperclip.options[:command_path] = "/usr/bin/"

  # Rails.application.config.middleware.use ExceptionNotification::Rack,
  #  :email => {
  #    :email_prefix => ENV["ERROR_PREFIX"],
  #    :sender_address => ENV["ERROR_SENDERS"],
  #    :exception_recipients => ENV["RECEIVERS"].split(", ")
  #  }

  #
  # Created new env variable in server .bashrc file as ENV["EMAIL_HOST"] to hold the domain name
  # And Changed below line with new env variable, ref: https://omnisling.atlassian.net/browse/OMNS-54
  # Changed By: Aravind Sankar
  # Date : 25 June 2018
  #
  #config.action_controller.asset_host = ENV["HOST"]
  config.action_mailer.asset_host = ENV["EMAIL_HOST"]
end"

ngnix.conf

" # For more information on configuration, see:

# * Official English Documentation: http://nginx.org/en/docs/

# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

# include /usr/local/nginx/conf/mime.types;

events {
    worker_connections 1024;
}

http {
    client_max_body_size 80M;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    gzip on;
    gzip_disable "msie6";
    include /etc/nginx/passenger.conf;

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

# Settings for a TLS enabled server.

# 

# server {

# listen       443 ssl http2 default_server;

# listen       [::]:443 ssl http2 default_server;

# server_name  _;

# root         /usr/share/nginx/html;

# root /home/deploy/omnisling/public;

# ssl_certificate "/etc/pki/nginx/server.crt";

# ssl_certificate_key "/etc/pki/nginx/private/server.key";

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout  10m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# 

# # Load configuration files for the default server block.

# include /etc/nginx/default.d/*.conf;

# 

# location / {

# }

# 

# error_page 404 /404.html;

# location = /40x.html {

# }

# 

# error_page 500 502 503 504 /50x.html;

# location = /50x.html {

# }

# }

}"

var/log/nginx/error.log

"2018/12/06 01:16:16 [error] 28064#0: *4 open() "/home/deploy/omnisling/develop/public/assets/os/pos-054e3367b9d18905b322b96613e13dd71c0721a5a1d647b5e8518909c38c288b.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/pos-054e3367b9d18905b322b96613e13dd71c0721a5a1d647b5e8518909c38c288b.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
2018/12/06 01:16:16 [error] 28064#0: *1 open() "/home/deploy/omnisling/develop/public/assets/os/ecommerce-ef0801aee6a3ded0a641d7626c7e34a51492f35e3b3e40c42b480f57c8e58917.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/ecommerce-ef0801aee6a3ded0a641d7626c7e34a51492f35e3b3e40c42b480f57c8e58917.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
2018/12/06 01:16:16 [error] 28064#0: *5 open() "/home/deploy/omnisling/develop/public/assets/os/mobile_apps-9ec5e2983b86b63469a8b5e41ba287dac94b62e615098973417c24eb34783bfe.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/mobile_apps-9ec5e2983b86b63469a8b5e41ba287dac94b62e615098973417c24eb34783bfe.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
2018/12/06 01:16:16 [error] 28064#0: *3 open() "/home/deploy/omnisling/develop/public/assets/os/cart-icon-7b627cb7122f2bdb354ff0caf1d4fe060a2bb26f6e35f73fd945d71d1115201e.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/cart-icon-7b627cb7122f2bdb354ff0caf1d4fe060a2bb26f6e35f73fd945d71d1115201e.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
2018/12/06 01:16:16 [error] 28064#0: *6 open() "/home/deploy/omnisling/develop/public/assets/os/pos_icon-7669c3f57465dbe3533a2ff738a867a04e31bf57aa0500d37897025921043c7b.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/pos_icon-7669c3f57465dbe3533a2ff738a867a04e31bf57aa0500d37897025921043c7b.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
2018/12/06 01:16:16 [error] 28064#0: *7 open() "/home/deploy/omnisling/develop/public/assets/os/mobile_apps_icon-c763792f0bcdf4d9332a1f72d163d7851df70dfcb8ba868e614773b3c30a2978.jpg" failed (2: No such file or directory), client: 106.51.74.45, server: localhost, request: "GET /assets/os/mobile_apps_icon-c763792f0bcdf4d9332a1f72d163d7851df70dfcb8ba868e614773b3c30a2978.jpg HTTP/1.1", host: "52.86.42.50", referrer: "http://52.86.42.50/"
"

任何帮助都将不胜感激。提前感谢。

nwsw7zdq

nwsw7zdq1#

共享您在生产公共资产文件夹中的内容。查找链轮清单文件。查找已预编译的资产,以确保编译按程序进行。
就像这样的链轮清单

fhity93d

fhity93d2#

这将使:

config.serve_static_assets = true

但面对“X内容类型选项:nosniff”相关的问题。
而实际的Rails有这样的功能:

config.public_file_server.enabled

然后一切正常。没有“X-Content-Type-Options:nosniff”错误。

相关问题