Setting up Nginx + Passenger » History » Version 7
Damien Churchill, 07/12/2018 10:50 AM
Add note about how nginx should be configured when using Passenger 5.
1 | 1 | Rytis Sileika | h1. Setting up Nginx + Passenger |
---|---|---|---|
2 | |||
3 | Passenger packages/repos are available at http://passenger.stealthymonkeys.com/ |
||
4 | |||
5 | 6 | Gabor Garami | h2. Nginx + Passenger with foreman on CentOS |
6 | 1 | Rytis Sileika | |
7 | Install packages |
||
8 | |||
9 | <pre> |
||
10 | # yum install -y nginx-passenger |
||
11 | </pre> |
||
12 | |||
13 | Create self signed certificate |
||
14 | |||
15 | <pre> |
||
16 | # cd /etc/nginx/ |
||
17 | # openssl genrsa -des3 -out server.key 1024 |
||
18 | # openssl req -new -key server.key -out server.csr |
||
19 | # cp server.key server.key.org |
||
20 | # openssl rsa -in server.key.org -out server.key |
||
21 | # openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt |
||
22 | </pre> |
||
23 | |||
24 | Make a local copy of the apps `public` directory (local to rails, as nginx/passenger doesn't seem to like symbolic links) |
||
25 | |||
26 | <pre> |
||
27 | # cd /usr/share/foreman |
||
28 | # rm public |
||
29 | # cp -a /var/lib/foreman/public . |
||
30 | </pre> |
||
31 | |||
32 | Add to `/etc/nginx/nginx.conf`: |
||
33 | |||
34 | <pre> |
||
35 | env PATH; |
||
36 | </pre> |
||
37 | |||
38 | Create foreman application config file `/etc/nginx/conf.d/foreman.conf`: |
||
39 | |||
40 | <pre> |
||
41 | server { |
||
42 | listen 443; |
||
43 | server_name _; |
||
44 | ssl on; |
||
45 | ssl_certificate /etc/nginx/server.crt; |
||
46 | ssl_certificate_key /etc/nginx/server.key; |
||
47 | 4 | Dominic Cleal | |
48 | # Verify puppetmaster clients against Puppet CA |
||
49 | ssl_crl /var/lib/puppet/ssl/ca/ca_crl.pem; |
||
50 | ssl_client_certificate /var/lib/puppet/ssl/certs/ca.pem; |
||
51 | ssl_verify_client optional; |
||
52 | ssl_verify_depth 1; |
||
53 | |||
54 | 1 | Rytis Sileika | access_log /var/log/nginx/foreman_access.log; |
55 | error_log /var/log/nginx/foreman_error.log debug; |
||
56 | root /usr/share/foreman/public; |
||
57 | 4 | Dominic Cleal | |
58 | 1 | Rytis Sileika | passenger_enabled on; |
59 | 4 | Dominic Cleal | passenger_set_cgi_param HTTPS on; |
60 | passenger_set_cgi_param SSL_CLIENT_S_DN $ssl_client_s_dn; |
||
61 | passenger_set_cgi_param SSL_CLIENT_VERIFY $ssl_client_verify; |
||
62 | |||
63 | 7 | Damien Churchill | # If using Passenger 5 then something similar to the following should be used, and the corresponding values updated in Settings/Authentication: |
64 | # passenger_env_var HTTPS on; |
||
65 | # passenger_set_header X-Client-DN $ssl_client_s_dn; # Set to HTTP_X_CLIENT_DN |
||
66 | # passenger_set_header X-Client-Verify $ssl_client_verify; # Set to HTTP_X_CLIENT_VERIFY |
||
67 | |||
68 | 1 | Rytis Sileika | #location / { |
69 | #} |
||
70 | } |
||
71 | </pre> |
||
72 | 4 | Dominic Cleal | |
73 | The SSL configuration here can verify clients for SSL communications with puppetmaster scripts, as per the "Securing Communications with SSL":http://theforeman.org/manuals/1.1/index.html#5.4SecuringCommunicationswithSSL documentation. It verifies clients using the Puppet CA and passes the information to Passenger and Foreman. |
||
74 | |||
75 | This guide uses a self-signed certificate for the Foreman server, so the ENC and report scripts will need to reference the certificate generated here in the @:ssl_ca@ and @$foreman_ssl_ca@ settings. |
||
76 | 5 | Sachar de Vries | |
77 | |||
78 | h2. Nginx + Passenger with foreman 1.2 on RHEL6.x/Scientific Linux |
||
79 | |||
80 | To run both puppermaster and foreman 1.2 on the same host using nginx + passenger an upgrade to phusion passenger 4.0 is required. To not break your existing puppetmaster setup, which uses the system supplied ruby follow the following steps: |
||
81 | |||
82 | setup assumes you are upgrading from foreman 1.1 and have a working nginx-passenger setup already. |
||
83 | |||
84 | <pre> |
||
85 | the current phusion supplied rpm is still a 3 version, so using yum upgrade won't help |
||
86 | yum info passenger-release |
||
87 | Loaded plugins: security |
||
88 | Available Packages |
||
89 | Name : passenger-release |
||
90 | Arch : noarch |
||
91 | Version : 3 |
||
92 | Release : 6.el6 |
||
93 | Size : 5.5 k |
||
94 | Repo : passenger |
||
95 | Summary : Phusion Passenger release RPM/Yum repository configuration |
||
96 | URL : http://passenger.stealthymonkeys.com/ |
||
97 | License : MIT |
||
98 | Description : Phusion Passenger Yum/RPM configuration. This package contains the Yum |
||
99 | : repository configuration to install & update Phusion Passenger, as |
||
100 | : well as the GPG signing key to verify them. |
||
101 | </pre> |
||
102 | |||
103 | So instead use gem to install the correct package (as per: https://www.phusionpassenger.com/download#open_source): |
||
104 | <pre> |
||
105 | 1 | Rytis Sileika | gem install passenger |
106 | 6 | Gabor Garami | Fetching: daemon_controller-1.1.4.gem (100%) |
107 | Fetching: passenger-4.0.5.gem (100%) |
||
108 | 5 | Sachar de Vries | Successfully installed daemon_controller-1.1.4 |
109 | Successfully installed passenger-4.0.5 |
||
110 | 2 gems installed |
||
111 | Installing ri documentation for daemon_controller-1.1.4... |
||
112 | Installing ri documentation for passenger-4.0.5... |
||
113 | Installing RDoc documentation for daemon_controller-1.1.4... |
||
114 | Installing RDoc documentation for passenger-4.0.5... |
||
115 | </pre> |
||
116 | |||
117 | Configure nginx: |
||
118 | you might need to install some packages ( yum install libcurl-devel libcurl ) |
||
119 | <pre> |
||
120 | passenger-install-nginx-module |
||
121 | Welcome to the Phusion Passenger Nginx module installer, v4.0.5. |
||
122 | |||
123 | This installer will guide you through the entire installation process. It |
||
124 | shouldn't take more than 5 minutes in total. |
||
125 | |||
126 | Here's what you can expect from the installation process: |
||
127 | |||
128 | 1. This installer will compile and install Nginx with Passenger support. |
||
129 | 2. You'll learn how to configure Passenger in Nginx. |
||
130 | 3. You'll learn how to deploy a Ruby on Rails application. |
||
131 | |||
132 | Don't worry if anything goes wrong. This installer will advise you on how to |
||
133 | solve any problems. |
||
134 | |||
135 | Press Enter to continue, or Ctrl-C to abort. |
||
136 | |||
137 | |||
138 | -------------------------------------------- |
||
139 | |||
140 | Checking for required software... |
||
141 | |||
142 | * Checking for GNU C compiler... |
||
143 | Found: yes |
||
144 | Location: /usr/bin/gcc |
||
145 | * Checking for GNU C++ compiler... |
||
146 | Found: yes |
||
147 | Location: /usr/bin/g++ |
||
148 | * Checking for A download tool like 'wget' or 'curl'... |
||
149 | Found: yes |
||
150 | Location: /usr/bin/wget |
||
151 | * Checking for Ruby development headers... |
||
152 | Found: yes |
||
153 | Location: /usr/lib64/ruby/1.8/x86_64-linux/ruby.h |
||
154 | * Checking for OpenSSL support for Ruby... |
||
155 | Found: yes |
||
156 | * Checking for RubyGems... |
||
157 | Found: yes |
||
158 | * Checking for Rake (associated with /usr/bin/ruby)... |
||
159 | Found: yes |
||
160 | Location: /usr/bin/ruby /usr/bin/rake |
||
161 | * Checking for rack... |
||
162 | Found: yes |
||
163 | * Checking for Curl development headers with SSL support... |
||
164 | Found: yes |
||
165 | Version: libcurl 7.19.7 |
||
166 | Usable: yes |
||
167 | curl-config location: /usr/bin/curl-config |
||
168 | Supports SSL: yes |
||
169 | Header location: /usr/include/curl/curl.h |
||
170 | * Checking for OpenSSL development headers... |
||
171 | Found: yes |
||
172 | Location: /usr/include/openssl/ssl.h |
||
173 | * Checking for Zlib development headers... |
||
174 | Found: yes |
||
175 | Location: /usr/include/zlib.h |
||
176 | </pre> |
||
177 | |||
178 | Stop nginx and update /etc/init.d/nginx to use the correct binary |
||
179 | <pre> |
||
180 | vi /etc/init.d/nginx |
||
181 | #nginx="/usr/sbin/nginx" |
||
182 | 1 | Rytis Sileika | nginx="/opt/nginx/sbin/nginx" |
183 | 5 | Sachar de Vries | </pre> |
184 | |||
185 | 6 | Gabor Garami | Make sure passenger.conf in /etc/nginx/conf,d still points to the system ruby passenger version |
186 | 5 | Sachar de Vries | <pre> |
187 | # cat passenger.conf |
||
188 | |||
189 | passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-4.0.5; |
||
190 | passenger_ruby /usr/bin/ruby; |
||
191 | </pre> |
||
192 | |||
193 | Update foreman.conf (do not set the passenger_root) |
||
194 | <pre> |
||
195 | # cat foreman.conf |
||
196 | |||
197 | server { |
||
198 | passenger_ruby /usr/bin/ruby193-ruby; |
||
199 | |||
200 | ..... |
||
201 | 1 | Rytis Sileika | } |
202 | <snip> |
||
203 | </pre> |
||
204 | |||
205 | 6 | Gabor Garami | Start nginx and check if the website is working now. |
206 | 1 | Rytis Sileika | |
207 | 6 | Gabor Garami | h2. Post-install setup for Foreman 1.1+ to support certificate authentication via Nginx |
208 | |||
209 | Starting from Foreman 1.1 it requires a bit more configuration because by default it supports only Apache webserver environment but Foreman also provides a configuration to make it fit to any other webserver. |
||
210 | |||
211 | Log in to the administration area and go to Administer -> Setting page. Find *ssl_client_dn_env* variable and set its value to @HTTP_X_CLIENT_DN@ . Also find *ssl_client_verify_env* and set it to @HTTP_X_CLIENT_VERIFY@ . |
||
212 | |||
213 | These modifications are required since nginx behaves a bit different than Apache and passes SSL certificate informations on different way. |
||
214 | |||
215 | If you plan to use Nginx for Puppet Master too, check the corresponding variables in puppet.conf: *ssl_client_header* and *ssl_client_verify_header* |
||
216 | |||
217 | http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_configuring_phusion_passenger has more information |