rails-nginx 1.0.0.pre.beta.4 → 1.0.0.pre.beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ad4b0a55bb318d4b480cd0c1853ef84d73e58a81852011af914cc34fa4dec0c
4
- data.tar.gz: d8424c2e24b3060628e99c2ebfa2f3913068b2275572a9509e29fb2719dbf77e
3
+ metadata.gz: '058189602280cfeeb47c1b5559b6f46be3ec9e28ae16cc14414a621c3a549b05'
4
+ data.tar.gz: 2fa39064a2fb2980faf7c637a66fca8dfb20ea6670ad5b4868a69006460a6f79
5
5
  SHA512:
6
- metadata.gz: dcda22bcae6a801ab6914bbd17dc5745a4d84936e531cd8b54d80e4a5a768984034d4c19e2f2cf74a961bb94ea5abc0c785735c34d2fff2d53ffd4164e6ac305
7
- data.tar.gz: 1d2bfaa5d649a45d79e351bb44ad17173208bf8691ed10e537723dd2e71fc82400786213d4885226e6950227ab4cf88322266c6534d2a6e28c80962ad7d2969f
6
+ metadata.gz: 2219d85b6fd63d594f2d12c33a18e5317b33b216cfc0531e67f4704c31967a347c4b1bb1951a33636a82bcec5a6109d9a707df440909f07cc716d74698a1dea2
7
+ data.tar.gz: 538294ecdf66eb548a36849242b2be90baa67736d311d6f3764c294e15b5464c6c843b834dfb4e70b84b8a6facf066d0558fe4efbcf983e7f7127cc6529a569c
data/README.md CHANGED
@@ -67,32 +67,31 @@ gem install rails-nginx
67
67
 
68
68
  Add the Puma plugin to your configuration, and limit it to your development environment.
69
69
 
70
- **config/puma.rb**
70
+ **File: config/puma.rb**
71
71
  ```ruby
72
72
  plugin :rails_nginx if Rails.env.development?
73
73
  ```
74
74
 
75
- > [!IMPORTANT]
76
- > **If you skip this, NGINX reverse proxy will have a randomized port while Puma will not. The reverse proxy will not work.**
77
- >
78
- > Puma's `port` configuration option makes it impossible for Rails NGINX to assign a random open port back to Puma.
79
- >
80
- > To fix this issue, simply remove it from our Puma configuration.
75
+ Then simply start Rails!
76
+
77
+ **Terminal**
78
+ ```
79
+ > ./bin/rails
80
+ ```
81
+
82
+ OR
83
+
84
+ ```
85
+ > ./bin/rails -p 3001
86
+ ```
87
+
88
+ > [!NOTE]
89
+ > Rails NGINX will clear all port bindings and assign back to Puma a random open port, or the provided Rails port parameter.
81
90
  >
82
- > **config/puma.rb**
91
+ > The following Puma configuration will be **ignored**.
83
92
  > ```ruby
84
93
  > port ENV.fetch("PORT") { 3000 }
85
94
  > ```
86
- >
87
- > OR simply disable it in your development environment:
88
- > ```ruby
89
- > port ENV.fetch("PORT") { 3000 } unless Rails.env.development?
90
- > ```
91
- >
92
- > OR always manually provide an open port when starting Rails:
93
- > ```
94
- > ./bin/rails server -p 3001
95
- > ```
96
95
 
97
96
  ### Default Configuration
98
97
  By default, Rails NGINX will configure [Ruby NGINX](https://github.com/bert-mccutchen/ruby-nginx) with the following options. For the examples, pretend I have an application called "HelloWorld".
@@ -108,6 +107,9 @@ By default, Rails NGINX will configure [Ruby NGINX](https://github.com/bert-mccu
108
107
  | `ssl_certificate_key_path` | `Rails.root` + `tmp/nginx/_[DOMAIN]-key.pem` | `/home/bert/hello_world/tmp/nginx/_hello-world.test-key.pem` |
109
108
  | `access_log_path` | `Rails.root` + `log/nginx/[DOMAIN].access.log` | `/home/bert/hello_world/log/hello-world.test.access.log` |
110
109
  | `error_log_path` | `Rails.root` + `log/nginx/[DOMAIN].error.log` | `/home/bert/hello_world/log/hello-world.test.error.log` |
110
+ | `skip_teardown`* | `false` | |
111
+
112
+ \* Skipping teardown simply leaves the NGINX configuration and hosts mapping in place. This can be useful if you require elevated permissions to change the hosts file, and you don't want to be asked to enter your credentials every time. Any attempts to visit the server's domain while the server is offline will result in a NGINX error page.
111
113
 
112
114
  ### Advanced Usage
113
115
 
@@ -30,6 +30,7 @@ Puma::Plugin.create do
30
30
  def config(puma_config)
31
31
  rails_port!
32
32
 
33
+ puma_config.clear_binds!
33
34
  puma_config.port Rails::Nginx.port
34
35
 
35
36
  puma_config.on_booted do
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rails
4
+ module Nginx
5
+ class Configuration
6
+ def initialize(options = {})
7
+ @options = options if rails_server?
8
+ end
9
+
10
+ def rails_server?
11
+ defined?(Rails::Server)
12
+ end
13
+
14
+ def teardown?
15
+ !@options[:skip_teardown]
16
+ end
17
+
18
+ def nginx_options
19
+ defaults.merge(@options).except(:skip_teardown)
20
+ end
21
+
22
+ private
23
+
24
+ def domain
25
+ @options[:domain] || "#{Rails.application.class.module_parent.name.underscore.dasherize}.test"
26
+ end
27
+
28
+ def defaults
29
+ {
30
+ domain: domain,
31
+ port: ENV["PORT"],
32
+ root_path: Rails.public_path,
33
+ template_path: File.expand_path("templates/nginx.conf.erb", __dir__),
34
+ ssl: true,
35
+ log: true,
36
+ ssl_certificate_path: Rails.root.join("tmp/nginx/_#{domain}.pem"),
37
+ ssl_certificate_key_path: Rails.root.join("tmp/nginx/_#{domain}-key.pem"),
38
+ access_log_path: Rails.root.join("log/nginx/#{domain}.access.log"),
39
+ error_log_path: Rails.root.join("log/nginx/#{domain}.error.log"),
40
+ skip_teardown: false
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
@@ -62,7 +62,8 @@ server {
62
62
  location @<%= name %> {
63
63
  proxy_pass http://<%= name %>;
64
64
  proxy_http_version 1.1;
65
- proxy_cache_bypass $http_upgrade;
65
+ proxy_no_cache 1;
66
+ proxy_cache_bypass 1;
66
67
 
67
68
  <% if options[:ssl] %>
68
69
  # proxy SSL
@@ -84,7 +85,8 @@ server {
84
85
  location ^~ /assets/ {
85
86
  proxy_pass http://<%= name %>;
86
87
  proxy_http_version 1.1;
87
- proxy_cache_bypass $http_upgrade;
88
+ proxy_no_cache 1;
89
+ proxy_cache_bypass 1;
88
90
 
89
91
  <% if options[:ssl] %>
90
92
  # proxy SSL
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rails
4
4
  module Nginx
5
- VERSION = "1.0.0-beta.4"
5
+ VERSION = "1.0.0-beta.6"
6
6
  end
7
7
  end
data/lib/rails/nginx.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "socket"
4
4
  require "ruby/nginx"
5
+ require_relative "nginx/configuration"
5
6
  require_relative "nginx/version"
6
7
 
7
8
  module Rails
@@ -13,9 +14,10 @@ module Rails
13
14
  end
14
15
 
15
16
  def self.start!(options = {}, &block)
16
- return unless rails_server?
17
+ rails_config = Configuration.new(options)
18
+ return unless rails_config.rails_server?
17
19
 
18
- config = Ruby::Nginx.add!(options.reverse_merge(defaults(options)), &block)
20
+ config = Ruby::Nginx.add!(rails_config.nginx_options, &block)
19
21
 
20
22
  puts start_message(config.options)
21
23
  rescue Ruby::Nginx::Error => e
@@ -23,38 +25,17 @@ module Rails
23
25
  end
24
26
 
25
27
  def self.stop!(options = {}, &block)
26
- return unless rails_server?
28
+ rails_config = Configuration.new(options)
29
+ return unless rails_config.rails_server? && rails_config.teardown?
27
30
 
28
- Ruby::Nginx.remove!(options.reverse_merge(defaults(options)), &block)
31
+ puts stop_message(rails_config.nginx_options)
32
+ Ruby::Nginx.remove!(rails_config.nginx_options, &block)
29
33
  rescue Ruby::Nginx::Error => e
30
34
  abort "[Ruby::Nginx] #{e.message}"
31
35
  end
32
36
 
33
37
  private
34
38
 
35
- def self.rails_server?
36
- defined?(Rails::Server)
37
- end
38
- private_class_method :rails_server?
39
-
40
- def self.defaults(options)
41
- domain = options[:domain] || "#{Rails.application.class.module_parent.name.underscore.dasherize}.test"
42
-
43
- {
44
- domain: domain,
45
- port: port,
46
- root_path: Rails.public_path,
47
- template_path: File.expand_path("nginx/templates/nginx.conf.erb", __dir__),
48
- ssl: true,
49
- log: true,
50
- ssl_certificate_path: Rails.root.join("tmp/nginx/_#{domain}.pem"),
51
- ssl_certificate_key_path: Rails.root.join("tmp/nginx/_#{domain}-key.pem"),
52
- access_log_path: Rails.root.join("log/nginx/#{domain}.access.log"),
53
- error_log_path: Rails.root.join("log/nginx/#{domain}.error.log")
54
- }
55
- end
56
- private_class_method :defaults
57
-
58
39
  def self.start_message(config)
59
40
  message = ["* Rails NGINX version: #{Rails::Nginx::VERSION}"]
60
41
  message << "* HTTP Endpoint: http://#{config[:domain]}"
@@ -65,5 +46,10 @@ module Rails
65
46
  message.join("\n")
66
47
  end
67
48
  private_class_method :start_message
49
+
50
+ def self.stop_message(config)
51
+ "- Tearing down Rails NGINX config: #{config[:domain]}"
52
+ end
53
+ private_class_method :stop_message
68
54
  end
69
55
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.4
4
+ version: 1.0.0.pre.beta.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bert McCutchen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.0.pre.beta.3
47
+ version: 1.0.0.pre.beta.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.0.pre.beta.3
54
+ version: 1.0.0.pre.beta.4
55
55
  description: Automatically configure NGINX with SSL upon boot for Rails applications.
56
56
  email:
57
57
  - mail@bertm.dev
@@ -64,6 +64,7 @@ files:
64
64
  - README.md
65
65
  - lib/puma/plugin/rails_nginx.rb
66
66
  - lib/rails/nginx.rb
67
+ - lib/rails/nginx/configuration.rb
67
68
  - lib/rails/nginx/templates/nginx.conf.erb
68
69
  - lib/rails/nginx/version.rb
69
70
  homepage: https://github.com/bert-mccutchen/rails-nginx