无法创建在 Rails 中有带前导点的段的路由(以验证 Let's Encrypt)
Can't create a route that has a segment with a leading dot in Rails (to verify Let's Encrypt)
在 Heroku 上的 Rails 5 应用程序中,我正在尝试为此 URL 创建一个路由:http://beta.example.com/.well-known/acme-challenge/some-key,这样我就可以使用 Let's Encrypt 验证我的服务器以获取一个 SSL 证书。但是我无法让路线在路线的任何段中使用前导点或句点,它只是 returns 404 Not Found.
换句话说,.well-known
开头的点搞砸了。我可以获得一条没有点的工作路线,或者如果点在其他地方(例如 well.known
),但如果点是段中的第一个字符,它就不起作用。
我是这样开始的:
get "/.well-known/acme-challenge/:id" => "pages#letsencrypt"
当这不起作用时,我尝试使用 (dynamic segment):
get ':letsencrypt_route/acme-challenge/:id', to: "pages#letsencrypt", letsencrypt_route: /[^\/]+/
这将在段中的任何位置允许一个点...除了第一个字符,这是我需要的地方。
知道是什么原因造成的吗?当我尝试导航到段中有前导点的 URL 时,它甚至没有在我的日志中显示任何内容,它只是立即显示 404.
我看到有些人在 Rails 4 和 Rails 5 上都遇到过这个问题,我在使用 Thin 或 Puma 时,在开发和生产中都遇到过这个问题。我也尝试过使用几个 letsencrypt gem,但它在同一点停止。
这是我的 Gemfile,其中包含两种环境中的 gem:
source "https://rubygems.org"
ruby "2.3.1"
gem "rails", "5.0.0.1"
gem "pg", "0.18.4" # postgresql database
gem "twitter-bootstrap-rails", "~> 3.2.2"
gem "active_median", "~> 0.1.0" # used with chartkick for graph reporting
gem "activerecord-session_store", require: false # save session to database
gem "acts-as-taggable-on", git: "https://github.com/mbleigh/acts-as-taggable-on" # tagging
gem "administrate", git: "https://github.com/heyogrady/administrate", branch: "rails5"
gem "analytics-ruby", "~> 2.0.0", require: "segment/analytics" # segment.io
gem "arel"
gem "autoprefixer-rails" # for CSS vendor prefixes
gem "bootbox-rails", "~>0.4" # wrappers for javascript dialogs
gem "bootstrap-switch-rails" # bootstrap-switch.js
gem "bourbon"
gem "bower-rails" # install front-end components
gem "browser" # For variants support
gem "carrierwave" # for handling file uploads
gem "carmen-rails" # country and region selection
gem "chartkick", "~> 1.2.4" # used to provide nice looking charts
gem "chronic" # natural language date parser
gem "codemirror-rails", ">= 5.11" # display source code in pattern library
gem "coffee-rails", ">= 4.1.1"
gem "coffee-script-source", ">= 1.8.0" # Coffee script source
gem "country_select" # HTML list of countries
gem "dalli" # for memcached
gem "delayed_job_active_record", ">= 4.1" # background job processing
gem "delayed_job_web", ">= 1.2.10" # web interface for delayed job
gem "devise", ">= 4.2.0"
gem "devise-async", git: "https://github.com/mhfs/devise-async", branch: "devise-4.x" # for user authentication
gem "flamegraph" # super pretty flame graphs
gem "fog", require: false # for handling s3
# gem "font_assets" # Handle Cross-Origin Resource Sharing on fonts
gem "font_assets", git: "https://github.com/ericallam/font_assets", ref: "457dcfddc4318e83679e9a0935612924b7717085"
gem "friendly_id", "~> 5.1.0"
gem "fullcontact" # social profile info from fullcontact.com
gem "fuzzy_match" # used by smart_csv_parser for contact & address mapping
gem "google-api-client", "< 0.9", require: "google/api_client" # connecting to Google API
gem "groupdate", "~> 2.1.1" # used with chartkick for graph reporting
gem "handy", git: "https://github.com/heyogrady/handy"
gem "hike" # finds files in a set of paths
gem "honeybadger" # for error tracking
gem "intercom-rails" # tracking user behavior
gem "jbuilder", ">= 2.4.1" # for building JSON
gem "jquery-fileupload-rails", "~> 0.4.6" # file uploads
gem "jquery-rails" # jQuery
gem "jquery-ui-rails" # jQuery UI
gem "json" # for parsing JSON
gem "kaminari" # pagination
gem "le" # logentries
gem "less-rails", ">= 2.7.1" # LESS => CSS
gem "lograge" # better log formatting
gem "mandrill-api" # sending and tracking emails
gem "mechanize" # for screen scraping
gem "memory_profiler" # lets us use rack-mini-profilers GC features
gem "mini_magick" # processing images
gem "newrelic_rpm" # monitor app performance
gem "nylas", "1.1.0" # emails, calendar, contacts via Nylas.com
gem "oink"
gem "omniauth" # third party authentication
gem "omniauth-google-oauth2" # Google authentication
gem "omnicontacts" # retrieve contacts from email providers
gem "open_uri_redirections" # allow OpenURI redirections from HTTP to HTTPS
gem "paper_trail" # maintain record of stripe plans & subscriptions
gem "prawn-labels" # PDF labels
gem "puma" # server
gem "public_activity" # for model activity tracking
gem "rack-mini-profiler", require: false # display page load time badge
gem "rack-timeout" # raise error if Puma doesn't respond in given time
gem "rack-zippy" # serve gzipped assets
gem "rails-deprecated_sanitizer" # Our app uses old sanitizer methods.
gem "react-rails", "~> 1.6.0"
gem "responders", "~> 2.0" # respond_with and respond_to methods
gem "rest-client"
gem "sass-rails", ">= 5.0.3"
gem "semantic-ui-sass", git: "https://github.com/heyogrady/semantic-ui-sass"
gem "select2-rails" # select/search/dropdown box
gem "selenium-webdriver", require: false # screen-scraping
gem "signet"
gem "simple_form", ">= 3.2.1" # forms made easy for rails
gem "sinatra", git: "https://github.com/sinatra/sinatra"
gem "stripe", "~> 1.15.0" # charging customers
gem "stripe_event" # Stripe webhook integration
gem "stackprof" # a stack profiler
gem "state_machines-activemodel", ">= 0.4.0.pre"
gem "state_machines-activerecord", ">= 0.4.0.pre"
gem "toastr-rails" # display toaster notifications
gem "therubyracer", platforms: :ruby
gem "turbolinks", "~> 5.0.0.beta" # faster page loads
gem "twilio-ruby" # phone and SMS services
gem "twitter-typeahead-rails", "~> 0.11.1.pre.corejavascript" # typeahead.js - autocomplete
gem "uglifier", ">= 1.0.3"
gem "uuidtools"
gem "valid_email" # email validation
gem "wicked" # multi-page wizard forms
gem "yaml_db", git: "https://github.com/heyogrady/yaml_db", branch: "monkey-patch-rails-5" # import/export yml->db
gem "yaml_dump", git: "https://github.com/vanboom/yaml_dump" # dump db records to yaml files
# gem "zeroclipboard-rails", "~> 0.1.1" # copy to clipboard
问题出在 rack-zippy gem 上。当我删除 gem 和初始化程序时,路由工作正常。
不确定根本原因是一般的 gzip 压缩,这个特殊的 gem,还是 gem 对于我的 Rails 5 应用程序显然是多余的。来自 rack-zippy github page:
Want to use rack-zippy with a Rails v4.2 or greater app? Its
recommended you don't! Rails 4.2+ now supports serving gzipped files
directly so there's no need for rack-zippy in Rails 4.2+ apps.
如果其他人遇到类似问题,我会寻找任何影响您的中间件的 gems 或定制。
在 Heroku 上的 Rails 5 应用程序中,我正在尝试为此 URL 创建一个路由:http://beta.example.com/.well-known/acme-challenge/some-key,这样我就可以使用 Let's Encrypt 验证我的服务器以获取一个 SSL 证书。但是我无法让路线在路线的任何段中使用前导点或句点,它只是 returns 404 Not Found.
换句话说,.well-known
开头的点搞砸了。我可以获得一条没有点的工作路线,或者如果点在其他地方(例如 well.known
),但如果点是段中的第一个字符,它就不起作用。
我是这样开始的:
get "/.well-known/acme-challenge/:id" => "pages#letsencrypt"
当这不起作用时,我尝试使用 (dynamic segment):
get ':letsencrypt_route/acme-challenge/:id', to: "pages#letsencrypt", letsencrypt_route: /[^\/]+/
这将在段中的任何位置允许一个点...除了第一个字符,这是我需要的地方。
知道是什么原因造成的吗?当我尝试导航到段中有前导点的 URL 时,它甚至没有在我的日志中显示任何内容,它只是立即显示 404.
我看到有些人在 Rails 4 和 Rails 5 上都遇到过这个问题,我在使用 Thin 或 Puma 时,在开发和生产中都遇到过这个问题。我也尝试过使用几个 letsencrypt gem,但它在同一点停止。
这是我的 Gemfile,其中包含两种环境中的 gem:
source "https://rubygems.org"
ruby "2.3.1"
gem "rails", "5.0.0.1"
gem "pg", "0.18.4" # postgresql database
gem "twitter-bootstrap-rails", "~> 3.2.2"
gem "active_median", "~> 0.1.0" # used with chartkick for graph reporting
gem "activerecord-session_store", require: false # save session to database
gem "acts-as-taggable-on", git: "https://github.com/mbleigh/acts-as-taggable-on" # tagging
gem "administrate", git: "https://github.com/heyogrady/administrate", branch: "rails5"
gem "analytics-ruby", "~> 2.0.0", require: "segment/analytics" # segment.io
gem "arel"
gem "autoprefixer-rails" # for CSS vendor prefixes
gem "bootbox-rails", "~>0.4" # wrappers for javascript dialogs
gem "bootstrap-switch-rails" # bootstrap-switch.js
gem "bourbon"
gem "bower-rails" # install front-end components
gem "browser" # For variants support
gem "carrierwave" # for handling file uploads
gem "carmen-rails" # country and region selection
gem "chartkick", "~> 1.2.4" # used to provide nice looking charts
gem "chronic" # natural language date parser
gem "codemirror-rails", ">= 5.11" # display source code in pattern library
gem "coffee-rails", ">= 4.1.1"
gem "coffee-script-source", ">= 1.8.0" # Coffee script source
gem "country_select" # HTML list of countries
gem "dalli" # for memcached
gem "delayed_job_active_record", ">= 4.1" # background job processing
gem "delayed_job_web", ">= 1.2.10" # web interface for delayed job
gem "devise", ">= 4.2.0"
gem "devise-async", git: "https://github.com/mhfs/devise-async", branch: "devise-4.x" # for user authentication
gem "flamegraph" # super pretty flame graphs
gem "fog", require: false # for handling s3
# gem "font_assets" # Handle Cross-Origin Resource Sharing on fonts
gem "font_assets", git: "https://github.com/ericallam/font_assets", ref: "457dcfddc4318e83679e9a0935612924b7717085"
gem "friendly_id", "~> 5.1.0"
gem "fullcontact" # social profile info from fullcontact.com
gem "fuzzy_match" # used by smart_csv_parser for contact & address mapping
gem "google-api-client", "< 0.9", require: "google/api_client" # connecting to Google API
gem "groupdate", "~> 2.1.1" # used with chartkick for graph reporting
gem "handy", git: "https://github.com/heyogrady/handy"
gem "hike" # finds files in a set of paths
gem "honeybadger" # for error tracking
gem "intercom-rails" # tracking user behavior
gem "jbuilder", ">= 2.4.1" # for building JSON
gem "jquery-fileupload-rails", "~> 0.4.6" # file uploads
gem "jquery-rails" # jQuery
gem "jquery-ui-rails" # jQuery UI
gem "json" # for parsing JSON
gem "kaminari" # pagination
gem "le" # logentries
gem "less-rails", ">= 2.7.1" # LESS => CSS
gem "lograge" # better log formatting
gem "mandrill-api" # sending and tracking emails
gem "mechanize" # for screen scraping
gem "memory_profiler" # lets us use rack-mini-profilers GC features
gem "mini_magick" # processing images
gem "newrelic_rpm" # monitor app performance
gem "nylas", "1.1.0" # emails, calendar, contacts via Nylas.com
gem "oink"
gem "omniauth" # third party authentication
gem "omniauth-google-oauth2" # Google authentication
gem "omnicontacts" # retrieve contacts from email providers
gem "open_uri_redirections" # allow OpenURI redirections from HTTP to HTTPS
gem "paper_trail" # maintain record of stripe plans & subscriptions
gem "prawn-labels" # PDF labels
gem "puma" # server
gem "public_activity" # for model activity tracking
gem "rack-mini-profiler", require: false # display page load time badge
gem "rack-timeout" # raise error if Puma doesn't respond in given time
gem "rack-zippy" # serve gzipped assets
gem "rails-deprecated_sanitizer" # Our app uses old sanitizer methods.
gem "react-rails", "~> 1.6.0"
gem "responders", "~> 2.0" # respond_with and respond_to methods
gem "rest-client"
gem "sass-rails", ">= 5.0.3"
gem "semantic-ui-sass", git: "https://github.com/heyogrady/semantic-ui-sass"
gem "select2-rails" # select/search/dropdown box
gem "selenium-webdriver", require: false # screen-scraping
gem "signet"
gem "simple_form", ">= 3.2.1" # forms made easy for rails
gem "sinatra", git: "https://github.com/sinatra/sinatra"
gem "stripe", "~> 1.15.0" # charging customers
gem "stripe_event" # Stripe webhook integration
gem "stackprof" # a stack profiler
gem "state_machines-activemodel", ">= 0.4.0.pre"
gem "state_machines-activerecord", ">= 0.4.0.pre"
gem "toastr-rails" # display toaster notifications
gem "therubyracer", platforms: :ruby
gem "turbolinks", "~> 5.0.0.beta" # faster page loads
gem "twilio-ruby" # phone and SMS services
gem "twitter-typeahead-rails", "~> 0.11.1.pre.corejavascript" # typeahead.js - autocomplete
gem "uglifier", ">= 1.0.3"
gem "uuidtools"
gem "valid_email" # email validation
gem "wicked" # multi-page wizard forms
gem "yaml_db", git: "https://github.com/heyogrady/yaml_db", branch: "monkey-patch-rails-5" # import/export yml->db
gem "yaml_dump", git: "https://github.com/vanboom/yaml_dump" # dump db records to yaml files
# gem "zeroclipboard-rails", "~> 0.1.1" # copy to clipboard
问题出在 rack-zippy gem 上。当我删除 gem 和初始化程序时,路由工作正常。
不确定根本原因是一般的 gzip 压缩,这个特殊的 gem,还是 gem 对于我的 Rails 5 应用程序显然是多余的。来自 rack-zippy github page:
Want to use rack-zippy with a Rails v4.2 or greater app? Its recommended you don't! Rails 4.2+ now supports serving gzipped files directly so there's no need for rack-zippy in Rails 4.2+ apps.
如果其他人遇到类似问题,我会寻找任何影响您的中间件的 gems 或定制。