nginx_stage 0.3.0

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.travis.yml +3 -0
  4. data/CHANGELOG.md +199 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +19 -0
  8. data/Rakefile +36 -0
  9. data/bin/node +15 -0
  10. data/bin/ood_ruby +38 -0
  11. data/bin/python +15 -0
  12. data/bin/ruby +15 -0
  13. data/lib/nginx_stage/application.rb +125 -0
  14. data/lib/nginx_stage/configuration.rb +418 -0
  15. data/lib/nginx_stage/errors.rb +46 -0
  16. data/lib/nginx_stage/generator.rb +139 -0
  17. data/lib/nginx_stage/generator_helpers.rb +68 -0
  18. data/lib/nginx_stage/generators/app_clean_generator.rb +38 -0
  19. data/lib/nginx_stage/generators/app_config_generator.rb +101 -0
  20. data/lib/nginx_stage/generators/app_list_generator.rb +24 -0
  21. data/lib/nginx_stage/generators/app_reset_generator.rb +54 -0
  22. data/lib/nginx_stage/generators/nginx_clean_generator.rb +61 -0
  23. data/lib/nginx_stage/generators/nginx_list_generator.rb +22 -0
  24. data/lib/nginx_stage/generators/nginx_process_generator.rb +47 -0
  25. data/lib/nginx_stage/generators/nginx_show_generator.rb +48 -0
  26. data/lib/nginx_stage/generators/pun_config_generator.rb +102 -0
  27. data/lib/nginx_stage/pid_file.rb +37 -0
  28. data/lib/nginx_stage/socket_file.rb +51 -0
  29. data/lib/nginx_stage/user.rb +75 -0
  30. data/lib/nginx_stage/version.rb +4 -0
  31. data/lib/nginx_stage/views/app_config_view.rb +42 -0
  32. data/lib/nginx_stage/views/pun_config_view.rb +144 -0
  33. data/lib/nginx_stage.rb +133 -0
  34. data/nginx_stage.gemspec +24 -0
  35. data/sbin/nginx_stage +7 -0
  36. data/share/nginx_stage_example.yml +166 -0
  37. data/templates/app.conf.erb +14 -0
  38. data/templates/pun.conf.erb +79 -0
  39. data/test/minitest_helper.rb +4 -0
  40. data/test/test_nginx_stage.rb +11 -0
  41. metadata +132 -0
@@ -0,0 +1,42 @@
1
+ module NginxStage
2
+ # A view used as context for the app config ERB template file
3
+ module AppConfigView
4
+ # The URI used to access the app from the browser
5
+ # @return [String] the app URI
6
+ def app_request_uri
7
+ "#{sub_uri}#{NginxStage.app_request_uri(env: env, owner: owner, name: name)}"
8
+ end
9
+
10
+ # Path to the app root on the local filesystem
11
+ # @return [String] path to app root
12
+ def app_root
13
+ NginxStage.app_root(env: env, owner: owner, name: name)
14
+ end
15
+
16
+ # The Passenger environment to run app under
17
+ # @return [String] Passenger app environment
18
+ def app_passenger_env
19
+ NginxStage.app_passenger_env(env: env, owner: owner, name: name)
20
+ end
21
+
22
+ # The token used to identify an app
23
+ # @return [String] unique app token
24
+ def app_token
25
+ NginxStage.app_token(env: env, owner: owner, name: name)
26
+ end
27
+
28
+ # Internal URI used to access filesystem from apps
29
+ # @return [String] the filesystem URI
30
+ def sendfile_uri
31
+ NginxStage.pun_sendfile_uri
32
+ end
33
+
34
+ # Path to the filesystem root where files are served from
35
+ # NB: Need to use a regular expression for user as this will be in a global
36
+ # app config that all users share
37
+ # @return [String] path to filesystem root
38
+ def sendfile_root
39
+ NginxStage.pun_sendfile_root(user: "[\w-]+")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,144 @@
1
+ module NginxStage
2
+ # A view used as context for the pun config ERB template file
3
+ module PunConfigView
4
+ # Primary group of the user
5
+ # @return [String] primary group of user
6
+ def group
7
+ user.group
8
+ end
9
+
10
+ # Path to the user's personal error.log
11
+ # @return [String] path to error log
12
+ def error_log_path
13
+ NginxStage.pun_error_log_path(user: user)
14
+ end
15
+
16
+ # Path to the user's personal access.log
17
+ # @return [String] path to access log
18
+ def access_log_path
19
+ NginxStage.pun_access_log_path(user: user)
20
+ end
21
+
22
+ # Path to the user's per-user NGINX pid file
23
+ # @return [String] path to pid file
24
+ def pid_path
25
+ NginxStage.pun_pid_path(user: user)
26
+ end
27
+
28
+ # Path to system-installed NGINX mime.types config file
29
+ # @return [String] path to system-installed NGINX mime.types config
30
+ def mime_types_path
31
+ NginxStage.mime_types_path
32
+ end
33
+
34
+ # Path to system-installed Passenger locations.ini file
35
+ # @return [String] path to Passenger locations.ini
36
+ def passenger_root
37
+ NginxStage.passenger_root
38
+ end
39
+
40
+ # Path to system-installed Ruby binary
41
+ # @return [String] the system-installed Ruby binary
42
+ def passenger_ruby
43
+ NginxStage.passenger_ruby
44
+ end
45
+
46
+ # Path to system-installed NodeJS binary
47
+ # @return [String] the system-installed NodeJS binary
48
+ def passenger_nodejs
49
+ NginxStage.passenger_nodejs
50
+ end
51
+
52
+ # Path to system-installed python binary
53
+ # @return [String] the system-installed python binary
54
+ def passenger_python
55
+ NginxStage.passenger_python
56
+ end
57
+
58
+ # Path to user's personal tmp root
59
+ # @return [String] path to tmp root
60
+ def tmp_root
61
+ NginxStage.pun_tmp_root(user: user)
62
+ end
63
+
64
+ # Path to the user's per-user NGINX socket file
65
+ # @return [String] path to socket file
66
+ def socket_path
67
+ NginxStage.pun_socket_path(user: user)
68
+ end
69
+
70
+ # Internal URI used to access filesystem from apps
71
+ # @return [String] the filesystem URI
72
+ def sendfile_uri
73
+ NginxStage.pun_sendfile_uri
74
+ end
75
+
76
+ # Path to the filesystem root where files are served from
77
+ # @return [String] path to filesystem root
78
+ def sendfile_root
79
+ NginxStage.pun_sendfile_root(user: user)
80
+ end
81
+
82
+ # Array of wildcard paths to app configs user has access to
83
+ # @return [Array<String>] list of wildcard app config paths
84
+ def app_configs
85
+ NginxStage.pun_app_configs(user: user).map do |envmt|
86
+ NginxStage.app_config_path envmt
87
+ end
88
+ end
89
+
90
+ # View used to confirm whether the user wants to restart the PUN to reload
91
+ # configuration changes
92
+ # @return [String] restart confirmation view
93
+ def restart_confirmation
94
+ <<-EOF.gsub("'", %q{\\\'})
95
+ <html>
96
+ <head>
97
+ <style>
98
+ body {
99
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
100
+ font-size: 16px;
101
+ line-height: 1.4;
102
+ color: #333;
103
+ font-weight: 300;
104
+ padding: 15px;
105
+ }
106
+ h2 {
107
+ font-weight: 500;
108
+ font-size: 30px;
109
+ }
110
+ .text-danger {
111
+ color: #a94442;
112
+ }
113
+ .btn-danger {
114
+ text-decoration: none;
115
+ font-weight: 400;
116
+ padding: 10px 16px;
117
+ border-radius: 6px;
118
+ color: #fff;
119
+ background-color: #d9534f;
120
+ }
121
+ </style>
122
+ </head>
123
+ <body>
124
+ <h2>
125
+ App has not been initialized or does not exist
126
+ </h2>
127
+ <p class="text-danger">
128
+ This is the first time this app has been launched in your per-user
129
+ NGINX (PUN) server. This requires a configuration change followed
130
+ by a restart of your PUN server. Be sure you save all the work you
131
+ are doing in other apps that have active websocket connections
132
+ (i.e., Shell App) and you complete all file uploads/downloads.
133
+ </p>
134
+ <p>
135
+ Clicking the "Initialize App" button will apply the configuration
136
+ change and restart your per-user NGINX (PUN) server.
137
+ </p>
138
+ <a href="#{app_init_url}" class="btn-danger">Initialize App</a>
139
+ </body>
140
+ </html>
141
+ EOF
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,133 @@
1
+ require_relative "nginx_stage/version"
2
+ require_relative "nginx_stage/configuration"
3
+ require_relative "nginx_stage/errors"
4
+ require_relative "nginx_stage/user"
5
+ require_relative "nginx_stage/pid_file"
6
+ require_relative "nginx_stage/socket_file"
7
+ require_relative "nginx_stage/views/pun_config_view"
8
+ require_relative "nginx_stage/views/app_config_view"
9
+ require_relative "nginx_stage/generator"
10
+ require_relative "nginx_stage/generators/pun_config_generator"
11
+ require_relative "nginx_stage/generators/app_config_generator"
12
+ require_relative "nginx_stage/generators/app_reset_generator"
13
+ require_relative "nginx_stage/generators/app_list_generator"
14
+ require_relative "nginx_stage/generators/app_clean_generator"
15
+ require_relative "nginx_stage/generators/nginx_process_generator"
16
+ require_relative "nginx_stage/generators/nginx_show_generator"
17
+ require_relative "nginx_stage/generators/nginx_list_generator"
18
+ require_relative "nginx_stage/generators/nginx_clean_generator"
19
+ require_relative "nginx_stage/application"
20
+
21
+ require 'etc'
22
+
23
+ # The main namespace for NginxStage. Provides a global configuration.
24
+ module NginxStage
25
+ # Root path of this library
26
+ # @return [String] root path of library
27
+ def self.root
28
+ File.dirname __dir__
29
+ end
30
+
31
+ # Path to the configuration file
32
+ # @return [String] path to config file
33
+ def self.config_file
34
+ ENV["NGINX_STAGE_CONFIG_FILE"] || '/etc/ood/config/nginx_stage.yml'
35
+ end
36
+
37
+ extend Configuration
38
+
39
+ # Regex used to parse an app request
40
+ # @example Dev app request
41
+ # parse_app_request(request: '/dev/rails1/structure/1')
42
+ # #=> {env: :dev, name: 'rails1'}
43
+ # @example User app request with owner Bob
44
+ # parse_app_request(request: '/usr/bob/fillsim/containers')
45
+ # #=> {env: :usr, owner: 'bob', name: 'fillsim'}
46
+ # @param request [String] the URI request used to access app
47
+ # @return [Hash] hash containing parsed information
48
+ # @raise [InvalidRequest] if the environment specified doesn't exist
49
+ def self.parse_app_request(request:)
50
+ app_info = {}
51
+ app_request_regex.each do |env, regex|
52
+ if matches = regex.match(request)
53
+ app_info[:env] = env
54
+ matches.names.each { |k| app_info[k.to_sym] = matches[k] }
55
+ break
56
+ end
57
+ end
58
+ raise InvalidRequest, "invalid request: #{request}" if app_info.empty?
59
+ app_info
60
+ end
61
+
62
+ # Arguments used during execution of nginx binary
63
+ # @example Start the per-user NGINX for user Bob
64
+ # nginx_args(user: 'bob')
65
+ # #=> ['-c', '/var/lib/nginx/config/puns/bob.conf']
66
+ # @example Stop the per-user NGINX for user Bob
67
+ # nginx_args(user: 'bob', signal: :stop)
68
+ # #=> ['-c', '/var/lib/nginx/config/puns/bob.conf', '-s', 'stop']
69
+ # @param user [String] the owner of the nginx process
70
+ # @param signal [Symbol] the signal sent to the nginx process
71
+ # @return [Array<String>] the shell arguments used to execute the nginx process
72
+ def self.nginx_args(user:, signal: nil)
73
+ args = ['-c', pun_config_path(user: user)]
74
+ args.push('-s', signal.to_s) if signal
75
+ args
76
+ end
77
+
78
+ # List of users with nginx processes running
79
+ # @return [Array<User>] the list of users with running nginx processes
80
+ def self.active_users
81
+ Dir[pun_pid_path(user: '*')].map{|v| User.new v[/#{pun_pid_path(user: '(.+)')}/, 1]}
82
+ end
83
+
84
+ # Get a hash of all the staged app configs
85
+ # @example List of all staged app configs
86
+ # staged_apps
87
+ # #=> {
88
+ # dev: [
89
+ # {owner: 'bob', name: 'rails1'},
90
+ # {owner: 'dan', name: 'fillsim'}
91
+ # ],
92
+ # usr: [
93
+ # {owner: 'bob', name: 'airsim'}
94
+ # ]
95
+ # }
96
+ # @return [Hash] the hash of app environments with list of corresponding apps
97
+ def self.staged_apps
98
+ staged_apps = {}
99
+ @app_config_path.each do |env, path|
100
+ staged_apps[env] = Dir[app_config_path(env: env, owner: '*', name: '*')].map do |v|
101
+ matches = /#{app_config_path(env: env, owner: '(?<owner>.+)', name: '(?<name>.+)')}/.match(v)
102
+ {
103
+ owner: matches.names.include?('owner') ? matches[:owner] : nil,
104
+ name: matches.names.include?('name') ? matches[:name] : nil
105
+ }
106
+ end
107
+ end
108
+ staged_apps
109
+ end
110
+
111
+ # Run Ruby block as a different user if possible
112
+ # NB: Will forego user switching if current process is not root-owned
113
+ # @param user [String, Fixnum, nil] the user or user id to switch to
114
+ # @yield [] Block to run as given user
115
+ def self.as_user(user, &block)
116
+ (Process.uid == 0) && user ? sudo(user, &block) : block.call
117
+ end
118
+
119
+ private
120
+ # Switch user/group effective id's as well as secondary groups
121
+ def self.sudo(user, &block)
122
+ passwd = (user.is_a? Fixnum) ? Etc.getpwuid(user) : Etc.getpwnam(user)
123
+ name, uid, gid = passwd.name, passwd.uid, passwd.gid
124
+ Process.initgroups(name, gid)
125
+ Process::GID.grant_privilege(gid)
126
+ Process::UID.grant_privilege(uid)
127
+ block.call
128
+ ensure
129
+ Process::UID.grant_privilege(0)
130
+ Process::GID.grant_privilege(0)
131
+ Process.initgroups('root', 0)
132
+ end
133
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nginx_stage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nginx_stage"
8
+ spec.version = NginxStage::VERSION
9
+ spec.authors = ["Jeremy Nicklas"]
10
+ spec.email = ["jnicklas@osc.edu"]
11
+ spec.summary = %q{Stage and control per-user NGINX processes.}
12
+ spec.description = %q{Command line interface to generating per-user NGINX configurations as well as launching and controlling the nginx process.}
13
+ spec.homepage = "https://www.osc.edu"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ end
data/sbin/nginx_stage ADDED
@@ -0,0 +1,7 @@
1
+ #!/opt/ood/nginx_stage/bin/ood_ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'nginx_stage'
5
+
6
+ # Start up the nginx_stage application
7
+ NginxStage::Application.start
@@ -0,0 +1,166 @@
1
+ #
2
+ # This is an example NginxStage CLI configuration file. It contains the
3
+ # configuration options that can be specified to meet your system requirements.
4
+ # See https://github.com/OSC/nginx_stage for detailed information about
5
+ # NginxStage. In particular see
6
+ # https://github.com/OSC/nginx_stage/blob/master/lib/nginx_stage/configuration.rb
7
+ # for a detailed list of all possible configuration options and their default
8
+ # settings.
9
+ #
10
+ # Below you can find the default values for each configuration option commented
11
+ # out. Feel free to uncomment it and make modifications or write your
12
+ # modifications directly below the commented defaults.
13
+ #
14
+
15
+ ---
16
+
17
+ # Location of the ERB templates used in the generation of the NGINX configs
18
+ #
19
+ #template_root: '/opt/ood/nginx_stage/templates'
20
+
21
+ # The reverse proxy daemon user used to access the Unix domain sockets
22
+ #
23
+ #proxy_user: 'apache'
24
+
25
+ # Path to system-installed NGINX binary
26
+ #
27
+ #nginx_bin: '/opt/rh/nginx16/root/usr/sbin/nginx'
28
+
29
+ # White-list of signals that can be sent to the NGINX process
30
+ #
31
+ #nginx_signals:
32
+ # - 'stop'
33
+ # - 'quit'
34
+ # - 'reopen'
35
+ # - 'reload'
36
+
37
+ # Path to system-installed NGINX 'mime.types' file
38
+ #
39
+ #mime_types_path: '/opt/rh/nginx16/root/etc/nginx/mime.types'
40
+
41
+ # Path to system-installed Passenger 'locations.ini' file
42
+ #
43
+ #passenger_root: '/opt/rh/rh-passenger40/root/usr/share/passenger/phusion_passenger/locations.ini'
44
+
45
+ # Path to system-installed Ruby binary
46
+ #
47
+ #passenger_ruby: '/opt/ood/nginx_stage/bin/ruby'
48
+
49
+ # Path to system-installed Node.js binary
50
+ # Set to `false` if you don't want this specified in nginx config
51
+ #
52
+ #passenger_nodejs: '/opt/ood/nginx_stage/bin/node'
53
+
54
+ # Path to system-installed Python binary
55
+ # Set to `false` if you don't want this specified in nginx config
56
+ #
57
+ #passenger_python: '/opt/ood/nginx_stage/bin/python'
58
+
59
+ # Root location of per-user NGINX configs
60
+ #
61
+ #pun_config_path: '/var/lib/nginx/config/puns/%{user}.conf'
62
+
63
+ # Root location of per-user NGINX tmp dirs
64
+ #
65
+ #pun_tmp_root: '/var/lib/nginx/tmp/%{user}'
66
+
67
+ # Path to the per-user NGINX access log
68
+ #
69
+ #pun_access_log_path: '/var/log/nginx/%{user}/access.log'
70
+
71
+ # Path to the per-user NGINX error log
72
+ #
73
+ #pun_error_log_path: '/var/log/nginx/%{user}/error.log'
74
+
75
+ # Path to the per-user NGINX pid file
76
+ #
77
+ #pun_pid_path: '/var/run/nginx/%{user}/passenger.pid'
78
+
79
+ # Path to the per-user NGINX socket file
80
+ #
81
+ #pun_socket_path: '/var/run/nginx/%{user}/passenger.sock'
82
+
83
+ # Path to the local filesystem root where the per-user NGINX process serves
84
+ # files from for the user making use of the sendfile feature in NGINX
85
+ #
86
+ #pun_sendfile_root: '/'
87
+
88
+ # The internal URI used to access the local filesystem for downloading files
89
+ # from the apps (not accessible directly by client browser)
90
+ #
91
+ #pun_sendfile_uri: '/sendfile'
92
+
93
+ # List of hashes helping define wildcard app config locations. These are the
94
+ # arguments for {#app_config_path}.
95
+ #
96
+ #pun_app_configs:
97
+ # - env: 'dev'
98
+ # owner: '%{user}'
99
+ # name: '*'
100
+ # - env: 'usr'
101
+ # owner: '*'
102
+ # name: '*'
103
+ # - env: 'sys'
104
+ # owner: ''
105
+ # name: '*'
106
+
107
+ # A hash detailing the path to the per-user NGINX app configs
108
+ #
109
+ #app_config_path:
110
+ # dev: '/var/lib/nginx/config/apps/dev/%{owner}/%{name}.conf'
111
+ # usr: '/var/lib/nginx/config/apps/usr/%{owner}/%{name}.conf'
112
+ # sys: '/var/lib/nginx/config/apps/sys/%{name}.conf'
113
+
114
+ # A hash detailing the locations on the file system where apps reside for the
115
+ # corresponding environment
116
+ #
117
+ #app_root:
118
+ # dev: '~%{owner}/ondemand/dev/%{name}'
119
+ # usr: '/var/www/ood/apps/usr/%{owner}/gateway/%{name}'
120
+ # sys: '/var/www/ood/apps/sys/%{name}'
121
+
122
+ # A hash detailing the app's request URI not including the base-URI
123
+ #
124
+ #app_request_uri:
125
+ # dev: '/dev/%{name}'
126
+ # usr: '/usr/%{owner}/%{name}'
127
+ # sys: '/sys/%{name}'
128
+
129
+ # A hash detailing the regular expressions used to define the app namespace
130
+ # from a given URI request. Should match {#app_request_uri}.
131
+ #
132
+ #app_request_regex:
133
+ # dev: '^/dev/(?<name>[-\w.]+)'
134
+ # usr: '^/usr/(?<owner>[\w]+)\/(?<name>[-\w.]+)'
135
+ # sys: '^/sys/(?<name>[-\w.]+)'
136
+
137
+ # A hash detailing the tokens used to identify individual apps
138
+ #
139
+ #app_token:
140
+ # dev: 'dev/%{owner}/%{name}'
141
+ # usr: 'usr/%{owner}/%{name}'
142
+ # sys: 'sys/%{name}'
143
+
144
+ # A hash detailing the Passenger environment to run the app under within the
145
+ # PUN
146
+ #
147
+ #app_passenger_env:
148
+ # dev: 'development'
149
+ # usr: 'production'
150
+ # sys: 'production'
151
+
152
+ # Regular expression used to validate a given user name. The user name supplied
153
+ # must match the regular expression to be considered valid.
154
+ #
155
+ #user_regex: '[\w@\.\-]+'
156
+
157
+ # Minimum user id required to generate per-user NGINX server as the requested
158
+ # user
159
+ #
160
+ #min_uid: 1000
161
+
162
+ # Restrict starting up per-user NGINX process as user with this shell.
163
+ # NB: This only affects the `pun` command, you are still able to start or stop
164
+ # the PUN using other commands (e.g., `nginx`, `nginx_clean`, ...)
165
+ #
166
+ #disabled_shell: '/access/denied'
@@ -0,0 +1,14 @@
1
+ location ~ ^<%= app_request_uri %>(/.*|$) {
2
+ alias <%= app_root %>/public$1;
3
+ passenger_base_uri <%= app_request_uri %>;
4
+ passenger_app_root <%= app_root %>;
5
+ passenger_document_root <%= app_root %>/public;
6
+ passenger_enabled on;
7
+
8
+ passenger_app_env <%= app_passenger_env %>;
9
+
10
+ # Give apps the ability to download files from filesystem
11
+ passenger_set_cgi_param HTTP_X_SENDFILE_TYPE X-Accel-Redirect;
12
+ passenger_set_cgi_param HTTP_X_ACCEL_MAPPING "<%= sendfile_root %>=<%= sendfile_uri %>"; # Passenger 4
13
+ # passenger_set_header X-Accel-Mapping "<%= sendfile_root %>=<%= sendfile_uri %>"; # Passenger 5
14
+ }
@@ -0,0 +1,79 @@
1
+ # Setup environment
2
+ env USER=<%= user %>;
3
+
4
+ user <%= user %> <%= group %>; ## Default: nobody
5
+ error_log <%= error_log_path %>;
6
+ pid <%= pid_path %>;
7
+ worker_processes 1; ## Default: 1
8
+
9
+ events {
10
+ worker_connections 1024; ## Default: 1024
11
+ }
12
+
13
+ http {
14
+ include <%= mime_types_path %>;
15
+
16
+ # Define passenger environment
17
+ passenger_root <%= passenger_root %>;
18
+ passenger_ruby <%= passenger_ruby %>;
19
+ <%- if passenger_nodejs -%>
20
+ passenger_nodejs <%= passenger_nodejs %>;
21
+ <%- end -%>
22
+ <%- if passenger_python -%>
23
+ passenger_python <%= passenger_python %>;
24
+ <%- end -%>
25
+
26
+ # Set passenger security measures
27
+ passenger_user_switching off;
28
+ passenger_default_user <%= user %>;
29
+ passenger_load_shell_envvars off;
30
+
31
+ # Kill all apps after they idle timeout
32
+ passenger_min_instances 0;
33
+
34
+ # Take advantage of Ruby preloader
35
+ #passenger_spawn_method smart;
36
+ #passenger_max_preloader_idle_time 0;
37
+
38
+ # Load all apps directly
39
+ passenger_spawn_method direct;
40
+
41
+ # Set an array of temp and cache file options for the per-user environment
42
+ client_body_temp_path <%= tmp_root %>/client_body;
43
+ proxy_temp_path <%= tmp_root %>/proxy_temp;
44
+ fastcgi_temp_path <%= tmp_root %>/fastcgi_temp;
45
+ uwsgi_temp_path <%= tmp_root %>/uwsgi_temp;
46
+ scgi_temp_path <%= tmp_root %>/scgi_temp;
47
+
48
+ default_type application/octet-stream;
49
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
50
+ '$status $body_bytes_sent "$http_referer" '
51
+ '"$http_user_agent" "$http_x_forwarded_for"';
52
+ access_log <%= access_log_path %> main;
53
+ sendfile on;
54
+ tcp_nopush on;
55
+ client_max_body_size 10G;
56
+
57
+ server {
58
+ listen unix:<%= socket_path %>;
59
+ server_name localhost;
60
+
61
+ <%- if app_init_url -%>
62
+ location / {
63
+ default_type text/html;
64
+ return 404 '<%= restart_confirmation %>';
65
+ }
66
+ <%- end -%>
67
+
68
+ # Give apps the ability to download files from filesystem
69
+ location <%= sendfile_uri %> {
70
+ internal;
71
+ alias "<%= sendfile_root %>";
72
+ }
73
+
74
+ # Include all app configs user has access to
75
+ <%- app_configs.each do |app_config| -%>
76
+ include <%= app_config %>;
77
+ <%- end -%>
78
+ }
79
+ }
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'nginx_stage'
3
+
4
+ require 'minitest/autorun'
@@ -0,0 +1,11 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestNginxStage < MiniTest::Unit::TestCase
4
+ def test_that_it_has_a_version_number
5
+ refute_nil ::NginxStage::VERSION
6
+ end
7
+
8
+ def test_it_does_something_useful
9
+ assert false
10
+ end
11
+ end