capistrano-simple-nginx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/capistrano-simple-nginx.gemspec +26 -0
- data/lib/capistrano-simple-nginx.rb +0 -0
- data/lib/capistrano/simple_nginx.rb +1 -0
- data/lib/capistrano/simple_nginx/helpers.rb +44 -0
- data/lib/capistrano/tasks/nginx.rake +35 -0
- data/lib/templates/nginx_conf.erb +57 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9ac6aadc4c603895f54113c81c07eda319dfa84
|
4
|
+
data.tar.gz: 05f828e9a45cadd79f04651acb3d459803eef407
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87f3c6256b086415f50c9467b6f3bc4354a9ad22f3c02c743d6c7b155f36f083be45a78c0e356b97ab0f511c65784a26011f91e03348125eb7d09e63dc266b81
|
7
|
+
data.tar.gz: b2c42cc8a15850231e5f067d8c5434d344cd01c93bcb23b982648de2bbc3daf1f2ae358ad0ac84711d0f995b30abef0da28ba88ee3f7fe024748bd58e8342e4c
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Capistrano::SimpleNginx
|
2
|
+
Support for Capistrano 3.x
|
3
|
+
|
4
|
+
## Installlation
|
5
|
+
|
6
|
+
Add this line to your application's `Gemfile`:
|
7
|
+
```
|
8
|
+
gem 'capistrano'
|
9
|
+
gem 'capistrano-simple-nginx', '~> 0.0.1'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then run:
|
13
|
+
```
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
Or install it yourself as:
|
17
|
+
```
|
18
|
+
$ gem install capistrano-simple-nginx
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Require in `Capfile`:
|
24
|
+
```
|
25
|
+
require 'capistrano/simple-nginx'
|
26
|
+
```
|
27
|
+
|
28
|
+
* Generate file config nginx, run:
|
29
|
+
```
|
30
|
+
$ cap production nginx:setup
|
31
|
+
```
|
32
|
+
|
33
|
+
* start|stop|restart nginx, run:
|
34
|
+
```
|
35
|
+
$ cap production nginx:start
|
36
|
+
$ cap production nginx:stop
|
37
|
+
$ cap production nginx:restart
|
38
|
+
```
|
39
|
+
|
40
|
+
You need add directory to sock file of app. Example using unicorn for app:
|
41
|
+
```
|
42
|
+
# in config/deploy.rb
|
43
|
+
set :nginx_upstream_file, "/tmp/unicorn.sock"
|
44
|
+
```
|
45
|
+
|
46
|
+
## Default config
|
47
|
+
|
48
|
+
```
|
49
|
+
set :nginx_listen_port, 80 #listen_port
|
50
|
+
set :nginx_server_name, "_" #server_name
|
51
|
+
set :nginx_upstream_name, -> { "#{fetch(:application)}" } # upstream name
|
52
|
+
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" } #file name config
|
53
|
+
set :nginx_fail_timeout, 0
|
54
|
+
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" } # access log file
|
55
|
+
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" } # error log file
|
56
|
+
set :nginx_upstream_file, -> { "/tmp/#{fetch(:application)}.sock" } # .sock file path
|
57
|
+
```
|
58
|
+
|
59
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "capistrano-simple-nginx"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
s.date = "2018-07-23"
|
10
|
+
s.summary = "Capistrano tasks for automatic nginx configuration"
|
11
|
+
s.description = <<-EOF.gsub(/^\s+/, '')
|
12
|
+
Capistrano tasks for automatic nginx configuration
|
13
|
+
Work *only* with Capistrano 3+
|
14
|
+
EOF
|
15
|
+
s.authors = ["truongkma"]
|
16
|
+
s.email = "nd.truong1902@gmail.com"
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.homepage = "https://github.com/truongkma/capistrano-simple-nginx"
|
20
|
+
s.license = "MIT"
|
21
|
+
|
22
|
+
s.add_runtime_dependency "capistrano", "~> 3.1"
|
23
|
+
s.add_runtime_dependency "sshkit", "~> 1.2"
|
24
|
+
|
25
|
+
s.add_development_dependency "rake", "~> 0"
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../tasks/nginx.rake", __FILE__)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module SimpleNginx
|
5
|
+
module Helpers
|
6
|
+
def template template_name
|
7
|
+
StringIO.new(template_to_s(template_name))
|
8
|
+
end
|
9
|
+
|
10
|
+
def template_to_s template_name
|
11
|
+
config_file = File.join(File.dirname(__FILE__), "../../templates/#{template_name}")
|
12
|
+
ERB.new(File.read(config_file), nil, '-').result(binding)
|
13
|
+
end
|
14
|
+
|
15
|
+
def sudo_upload! from, to
|
16
|
+
filename = File.basename(to)
|
17
|
+
to_dir = File.dirname(to)
|
18
|
+
tmp_file = "/tmp/#{filename}"
|
19
|
+
upload! from, tmp_file
|
20
|
+
sudo :mv, tmp_file, to_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_exists? path
|
24
|
+
test "[ -e #{path} ]"
|
25
|
+
end
|
26
|
+
|
27
|
+
def deploy_user
|
28
|
+
capture :id, '-un'
|
29
|
+
end
|
30
|
+
|
31
|
+
def os_is_ubuntu?
|
32
|
+
capture(:cat, "/etc/*-release").include? "ubuntu"
|
33
|
+
end
|
34
|
+
|
35
|
+
def nginx_config_file
|
36
|
+
if os_is_ubuntu?
|
37
|
+
"/etc/nginx/sites-available/#{fetch(:nginx_config_name)}.conf"
|
38
|
+
else
|
39
|
+
"/etc/nginx/conf.d/#{fetch(:nginx_config_name)}.conf"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'capistrano/simple_nginx/helpers'
|
2
|
+
include Capistrano::SimpleNginx::Helpers
|
3
|
+
|
4
|
+
namespace :load do
|
5
|
+
task :defaults do
|
6
|
+
set :nginx_listen_port, 80
|
7
|
+
set :nginx_server_name, "_"
|
8
|
+
set :nginx_upstream_name, -> { "#{fetch(:application)}" }
|
9
|
+
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
|
10
|
+
set :nginx_fail_timeout, 0
|
11
|
+
set :nginx_access_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.access.log" }
|
12
|
+
set :nginx_error_log_file, -> { "/var/log/nginx/#{fetch(:nginx_config_name)}.error.log" }
|
13
|
+
set :nginx_upstream_file, -> { "/tmp/#{fetch(:application)}.sock" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :nginx do
|
18
|
+
desc 'Setup nginx configuration'
|
19
|
+
task :setup do
|
20
|
+
on roles :web do
|
21
|
+
unless file_exists?(nginx_config_file)
|
22
|
+
sudo_upload! template('nginx_conf.erb'), nginx_config_file
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
%w[stop start restart reload].each do |action|
|
28
|
+
desc "#{action} nginx"
|
29
|
+
task action do
|
30
|
+
on roles :web do
|
31
|
+
sudo :service, "nginx", action
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
upstream <%= fetch(:nginx_upstream_name) %> {
|
2
|
+
server unix:<%= fetch(:nginx_upstream_file) %> fail_timeout=<%= fetch(:nginx_fail_timeout) %>;
|
3
|
+
}
|
4
|
+
|
5
|
+
server {
|
6
|
+
server_tokens off;
|
7
|
+
add_header X-Content-Type-Options nosniff;
|
8
|
+
client_max_body_size 4G;
|
9
|
+
keepalive_timeout 10;
|
10
|
+
|
11
|
+
error_page 500 502 504 /500.html;
|
12
|
+
error_page 503 @503;
|
13
|
+
|
14
|
+
server_name <%= fetch(:nginx_server_name) %>;
|
15
|
+
root <%= current_path %>/public;
|
16
|
+
try_files $uri/index.html $uri @<%= fetch(:nginx_upstream_name) %>;
|
17
|
+
|
18
|
+
location @<%= fetch(:nginx_upstream_name) %> {
|
19
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
20
|
+
proxy_set_header Host $http_host;
|
21
|
+
proxy_redirect off;
|
22
|
+
proxy_pass http://<%= fetch(:nginx_upstream_name) %>;
|
23
|
+
|
24
|
+
access_log <%= fetch(:nginx_access_log_file) %>;
|
25
|
+
error_log <%= fetch(:nginx_error_log_file) %>;
|
26
|
+
}
|
27
|
+
|
28
|
+
location ^~ /assets/ {
|
29
|
+
gzip_static on;
|
30
|
+
expires max;
|
31
|
+
add_header Cache-Control public;
|
32
|
+
}
|
33
|
+
|
34
|
+
location = /50x.html {
|
35
|
+
root html;
|
36
|
+
}
|
37
|
+
|
38
|
+
location = /404.html {
|
39
|
+
root html;
|
40
|
+
}
|
41
|
+
|
42
|
+
location @503 {
|
43
|
+
error_page 405 = /system/maintenance.html;
|
44
|
+
if (-f $document_root/system/maintenance.html) {
|
45
|
+
rewrite ^(.*)$ /system/maintenance.html break;
|
46
|
+
}
|
47
|
+
rewrite ^(.*)$ /503.html break;
|
48
|
+
}
|
49
|
+
|
50
|
+
if ($request_method !~ ^(GET|HEAD|PUT|PATCH|POST|DELETE|OPTIONS)$ ){
|
51
|
+
return 405;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (-f $document_root/system/maintenance.html) {
|
55
|
+
return 503;
|
56
|
+
}
|
57
|
+
}
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-simple-nginx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- truongkma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sshkit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
Capistrano tasks for automatic nginx configuration
|
57
|
+
Work *only* with Capistrano 3+
|
58
|
+
email: nd.truong1902@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- capistrano-simple-nginx.gemspec
|
67
|
+
- lib/capistrano-simple-nginx.rb
|
68
|
+
- lib/capistrano/simple_nginx.rb
|
69
|
+
- lib/capistrano/simple_nginx/helpers.rb
|
70
|
+
- lib/capistrano/tasks/nginx.rake
|
71
|
+
- lib/templates/nginx_conf.erb
|
72
|
+
homepage: https://github.com/truongkma/capistrano-simple-nginx
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Capistrano tasks for automatic nginx configuration
|
96
|
+
test_files: []
|