/
Users guide Nginx.txt
1667 lines (1269 loc) · 63.9 KB
/
Users guide Nginx.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
= Phusion Passenger users guide, Nginx version =
image:images/phusion_banner.png[link="http://www.phusion.nl/"]
Phusion Passenger is an Nginx module, which makes deploying Ruby and Ruby on
Rails applications on Nginx a breeze. It follows the usual Ruby on Rails
conventions, such as "Don't-Repeat-Yourself" and ease of setup, while at the
same time providing enough flexibility.
This users guide will teach you:
- How to install Nginx with Phusion Passenger support.
- How to configure Phusion Passenger.
- How to deploy a Ruby on Rails application.
- How to deploy a link:http://rack.rubyforge.org/[Rack]-based Ruby application.
- How to solve common problems.
This guide assumes that the reader is somewhat familiar with Nginx and with
using the commandline.
== Support information ==
=== Supported operating systems ===
Phusion Passenger works on any POSIX-compliant operating system. In other
words: practically any operating system on earth, except Microsoft Windows.
Phusion Passenger is confirmed on a large number of operating systems and Linux
distributions, including, but not limited to, Ubuntu, Debian, CentOS/Fedora/RHEL,
Gentoo, Mac OS X, FreeBSD and Solaris. Both 32-bit and 64-bit platforms are supported.
Please
link:http://code.google.com/p/phusion-passenger/issues/list[report a bug]
or
link:http://groups.google.com/group/phusion-passenger[join our discussion forum]
if it doesn't work on your POSIX-compliant operating system.
=== Where to get support ===
* link:http://code.google.com/p/phusion-passenger/issues/list[Issue tracker] - report
bugs here.
* link:http://groups.google.com/group/phusion-passenger[Discussion forum] - post a
message here if you're experiencing problems.
== Installing Phusion Passenger ==
=== Overview ===
As you might already know, Nginx does not support loadable modules, in contrast
to most other web servers (e.g. Apache). Therefore, to install Phusion Passenger
for Nginx, one must recompile and reinstall Nginx with Phusion Passenger support.
There are two ways to do this:
1. By running the Phusion Passenger installer for Nginx. This installer will
guide you through the entire installation process, including downloading,
compiling and installing Nginx. You should be able to get Nginx with Phusion
Passenger support up-and-running in a matter of minutes. This is the
recommended installation method.
2. By manually configuring and compiling Nginx with Phusion Passenger support,
through Nginx's `--add-module` configure option. Generally, using our
installer is easier, so you should only use this method if you're already
familiar with compiling Nginx.
TIP: You might have to run the installation commands in the following sections
as 'root'. If the installer fails because of permission errors, it will tell
you.
[[specifying_ruby_installation]]
=== Specifying the correct Ruby installation ===
If your system has multiple Ruby installations -- which is likely the case on
MacOS X, or if you've also installed
link:http://www.rubyenterpriseedition.com[Ruby Enterprise Edition] -- then you
will need to tell the operating system which Ruby installation to use, prior to
running the Phusion Passenger installer. If you only have one Ruby installation
(the case on most Linux systems), then you can skip this section because Phusion
Passenger will automatically detect it.
To specify a Ruby installation, prepend your Ruby installation's `bin`
directory to the `PATH` environment variable. For example, if you have the
following Ruby installations:
- /usr/bin/ruby
- /opt/myruby/bin/ruby
and you want to use the latter, then type:
----------------------------------
export PATH=/opt/myruby/bin:$PATH
----------------------------------
=== Installing Phusion Passenger for Nginx through the installer ===
==== Obtaining the Phusion Passenger files and running the installer ====
You must obtain the Phusion Passenger files in order to run the installer.
This can be done either by installing the Phusion Passenger gem, or by
downloading the source tarball.
===== Gem =====
First, install the Phusion Passenger gem by running:
---------------------------------
gem install passenger
---------------------------------
Next, run the Phusion Passenger installer for Nginx:
---------------------------------
passenger-install-nginx-module
---------------------------------
Please follow the instructions given by the installer.
===== Source tarball =====
The source tarball can be download from the
link:http://www.modrails.com/[Phusion Passenger website]. Extract the tarball to
whatever location you prefer. *The Phusion Passenger files are to reside in that
location permanently.* For example, if you would like Phusion Passenger to
reside in `/opt/passenger-x.x.x`, then type:
--------------------------------------------------------------
cd /opt
tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz
--------------------------------------------------------------
Next, run the Phusion Passenger installer for Nginx:
--------------------------------------------------------------
/opt/passenger-x.x.x/bin/passenger-install-nginx-module
--------------------------------------------------------------
Please follow the instructions given by the installer.
IMPORTANT: Please do not remove the passenger-x.x.x folder after installation.
Furthermore, the passenger-x.x.x folder must be accessible by Nginx.
==== Non-interactive/automatic installation ====
By default, the installer is interactive. If you want to automate installation,
then you can do so by passing various answers to the installer through command
line options.
Please run the installer with `--help` for a list of available command line
options.
=== Installing Phusion Passenger for Nginx manually ===
You can also install Phusion Passenger the way you install any other Nginx module.
To do this, run Nginx's configure script with `--add-module=/path-to-passenger-root/ext/nginx`.
If you installed Phusion Passenger via the gem, then 'path-to-passenger-root'
can be obtained with the command:
--------------------------
passenger-config --root
--------------------------
This will probably output something along the lines of '/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x',
so you'll probably have to specify something like `--add-module=/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x/ext/nginx`.
If you installed Phusion Passenger via a source tarball, then 'path-to-passenger-root'
is the directory which contains the Phusion Passenger source code. So if you
extracted the Phusion Passenger source code to '/opt/passenger-x.x.x', then you'll
have to specify `--add-module=/opt/passenger-x.x.x/ext/nginx`.
After having installed Nginx with Phusion Passenger support, you must paste the following
line into your Nginx configuration file:
------------------------------------------
passenger_root /path-to-passenger-root;
------------------------------------------
After having done so, restart Nginx.
=== Upgrading or downgrading Phusion Passenger or Nginx itself ===
Whether you're upgrading/downgrading Phusion Passenger or Nginx itself (or perhaps both),
Nginx will have to be recompiled and reinstalled. The procedure is exactly the same as
a normal installation so just follow the instructions in section 2.3 or 2.4.
When following the installation instructions, eventually `passenger-install-nginx-module`
or this document will instruct you to copy & paste some settings into the Nginx
configuration file; something that looks along the lines of:
------------------------------------------
passenger_root ...;
passenger_ruby ...;
------------------------------------------
Because you already had Phusion Passenger installed, you already had similar settings
in your Nginx configuration file, just with different values. *Replace* the old settings with
the new ones that you are instructed to paste. It is important that the old settings are
removed, otherwise Phusion Passenger may malfunction.
When you're done, restart Nginx.
=== Unloading (disabling) Phusion Passenger from Nginx without uninstalling it ===
You can temporarily unload (disable) Phusion Passenger from Nginx, without
uninstalling the Phusion Passenger files, so that Nginx behaves as if Phusion
Passenger was never installed in the first place. This might be useful to you if,
for example, you seem to be experiencing a problem caused by Phusion Passenger,
but you want to make sure whether that's actually the case, without having
to go through the hassle of uninstalling Phusion Passenger completely. When disabled,
Phusion Passenger will not occupy any memory or CPU or otherwise interfere with
Nginx.
To unload Phusion Passenger, edit your Nginx configuration file(s)
and comment out all Phusion Passenger configuration directives.
For example, if your configuration file looks like this...
-----------------------------------
...
http {
passenger_root /somewhere/passenger-x.x.x;
passenger_ruby /usr/bin/ruby;
passenger_max_pool_size 10;
gzip on;
server {
server_name www.foo.com;
listen 80;
root /webapps/foo/public;
passenger_enabled on;
passenger_use_global_queue on;
}
}
-----------------------------------
...then comment out the relevant directives, so that it looks like this:
-----------------------------------
...
http {
# passenger_root /somewhere/passenger-x.x.x;
# passenger_ruby /usr/bin/ruby;
# passenger_max_pool_size 10;
gzip on;
server {
server_name www.foo.com;
listen 80;
root /webapps/foo/public;
# passenger_enabled on;
# passenger_use_global_queue on;
}
}
-----------------------------------
After you've done this, save the file and restart Nginx.
=== Uninstalling Phusion Passenger ===
To uninstall Phusion Passenger, please first remove all Phusion Passenger
configuration directives from your Nginx configuration file(s). After you've
done this, you need to remove the Phusion Passenger files.
- If you installed Phusion Passenger via a gem, then type `gem uninstall passenger`.
You might have to run this as root.
- If you installed Phusion Passenger via a source tarball, then remove the directory
in which you placed the extracted Phusion Passenger files. This directory is the
same as the one pointed to the by 'PassengerRoot' configuration directive.
After having done so, recompile and reinstall Nginx itself, this time without
Phusion Passenger support, in order to purge any Phusion Passenger code from the
Nginx binary.
[[deploying_a_ror_app]]
== Deploying a Ruby on Rails 1.x or 2.x (but NOT Rails >= 3) application ==
Suppose you have a Ruby on Rails application in '/webapps/mycook', and you own
the domain 'www.mycook.com'. You can either deploy your application to the
virtual host's root (i.e. the application will be accessible from the root URL,
'http://www.mycook.com/'), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as 'http://www.mycook.com/railsapplication').
NOTE: The default `RAILS_ENV` environment in which deployed Rails applications
are run, is ``production''. You can change this by changing the
<<RailsEnv,rails_env>> configuration option.
=== Deploying to a virtual host's root ===
Add a 'server' virtual host entry to your Nginx configuration file. The virtual
host's root must point to your Ruby on Rails application's 'public' folder.
Inside the 'server' block, set 'passenger_enabled on'.
For example:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.mycook.com;
root /webapps/mycook/public;
passenger_enabled on;
}
...
}
-------------------------------------------
Then restart Nginx. The application has now been deployed.
[[deploying_rails_to_sub_uri]]
=== Deploying to a sub URI ===
Suppose that you already have a 'server' virtual host entry:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
}
...
}
-------------------------------------------
And you want your Ruby on Rails application to be accessible from the URL
'http://www.phusion.nl/rails'.
To do this, make a symlink in the virtual host's document root, and have it
point to your Ruby on Rails application's 'public' folder. For example:
-------------------------------------------
ln -s /webapps/mycook/public /websites/phusion/rails
-------------------------------------------
Next, set 'passenger_enabled on' and add a <<PassengerBaseURI,passenger_base_uri>>
option to the 'server' block:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rails; # <--- been added.
}
...
}
-------------------------------------------
Then restart Nginx. The application has now been deployed.
[TIP]
======================================
You can deploy multiple Rails applications under a virtual host, by specifying
<<PassengerBaseURI,passenger_base_uri>> multiple times. For example:
---------------------------------
server {
...
passenger_base_uri /app1;
passenger_base_uri /app2;
passenger_base_uri /app3;
}
---------------------------------
======================================
=== Redeploying (restarting the Ruby on Rails application) ===
Deploying a new version of a Ruby on Rails application is as simple as
re-uploading the application files, and restarting the application.
There are two ways to restart the application:
1. By restarting Nginx.
2. By creating or modifying the file 'tmp/restart.txt' in the Rails
application's <<application_root,root folder>>. Phusion Passenger will
automatically restart the application during the next request.
For example, to restart our example MyCook application, we type this in the
command line:
-------------------------------------------
touch /webapps/mycook/tmp/restart.txt
-------------------------------------------
Please note that, unlike earlier versions of Phusion Passenger, 'restart.txt'
is not automatically deleted. Phusion Passenger checks whether the timestamp
of this file has changed in order to determine whether the application should
be restarted.
=== Migrations ===
Phusion Passenger is not related to Ruby on Rails migrations in any way. To
run migrations on your deployment server, please login to your deployment
server (e.g. with 'ssh') and type `rake db:migrate RAILS_ENV=production` in
a shell console, just like one would normally run migrations.
=== Capistrano integration ===
See <<capistrano,Capistrano recipe>>.
[[deploying_a_rack_app]]
== Deploying a Rack-based Ruby application (including Rails >= 3) ==
Phusion Passenger supports arbitrary Ruby web applications that follow the
link:http://rack.rubyforge.org/[Rack] interface.
Phusion Passenger assumes that Rack application directories have a certain layout.
Suppose that you have a Rack application in '/webapps/rackapp'. Then that
folder must contain at least three entries:
- 'config.ru', a Rackup file for starting the Rack application. This file must contain
the complete logic for initializing the application.
- 'public/', a folder containing public static web assets, like images and stylesheets.
- 'tmp/', used for 'restart.txt' (our application restart mechanism). This will
be explained in a following subsection.
So '/webapps/rackapp' must, at minimum, look like this:
----------------------
/webapps/rackapp
|
+-- config.ru
|
+-- public/
|
+-- tmp/
----------------------
Suppose you own the domain 'www.rackapp.com'. You can either deploy your application
to the virtual host's root (i.e. the application will be accessible from the root URL,
'http://www.rackapp.com/'), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as 'http://www.rackapp.com/rackapp').
NOTE: The default `RACK_ENV` environment in which deployed Rack applications
are run, is ``production''. You can change this by changing the
<<RackEnv,rack_env>> configuration option.
=== Tutorial/example: writing and deploying a Hello World Rack application ===
First we create a Phusion Passenger-compliant Rack directory structure:
-------------------------------------------
$ mkdir /webapps/rack_example
$ mkdir /webapps/rack_example/public
$ mkdir /webapps/rack_example/tmp
-------------------------------------------
Next, we write a minimal "hello world" Rack application:
-------------------------------------------
$ cd /webapps/rack_example
$ some_awesome_editor config.ru
...type in some source code...
$ cat config.ru
app = proc do |env|
[200, { "Content-Type" => "text/html" }, ["hello <b>world</b>"]]
end
run app
-------------------------------------------
Finally, we deploy it by adding the following configuration options to
the Nginx configuration file:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.rackexample.com;
root /webapps/rack_example/public;
passenger_enabled on;
}
...
}
-------------------------------------------
And we're done! After an Nginx restart, the above Rack application will be available
under the URL 'http://www.rackexample.com/'.
=== Deploying to a virtual host's root ===
Add a 'server' virtual host entry to your Nginx configuration file. The virtual host's
root must point to your Rack application's 'public' folder. You must also set
'passenger_enabled on' in the 'server' block.
For example:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.rackapp.com;
root /webapps/rackapp/public;
passenger_enabled on;
}
...
}
-------------------------------------------
Then restart Nginx. The application has now been deployed.
[[deploying_rack_to_sub_uri]]
=== Deploying to a sub URI ===
Suppose that you already have a virtual host:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on;
}
...
}
-------------------------------------------
And you want your Rack application to be accessible from the URL
'http://www.phusion.nl/rack'.
To do this, make a symlink in the virtual host's document root, and have it
point to your Rack application's 'public' folder. For example:
-------------------------------------------
ln -s /webapps/rackapp/public /websites/phusion/rack
-------------------------------------------
Next, set 'passenger_enabled on' and add a <<PassengerBaseURI,passenger_base_uri>>
option to the 'server' block:
-------------------------------------------
http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rack; # <--- been added.
}
...
}
-------------------------------------------
Then restart Nginx. The application has now been deployed.
[TIP]
======================================
You can deploy multiple Rack applications under a virtual host, by specifying
<<PassengerBaseURI,passenger_base_uri>> multiple times. For example:
---------------------------------
server {
...
passenger_base_uri /app1;
passenger_base_uri /app2;
passenger_base_uri /app3;
}
---------------------------------
======================================
=== Redeploying (restarting the Rack application) ===
Deploying a new version of a Rack application is as simple as
re-uploading the application files, and restarting the application.
There are two ways to restart the application:
1. By restarting Nginx.
2. By creating or modifying the file 'tmp/restart.txt' in the Rack
application's <<application_root,root folder>>. Phusion Passenger will
automatically restart the application.
For example, to restart our example application, we type this in the
command line:
-------------------------------------------
touch /webapps/rackapp/tmp/restart.txt
-------------------------------------------
=== Rackup specifications for various web frameworks ===
include::users_guide_snippets/rackup_specifications.txt[]
== Configuring Phusion Passenger ==
After installation, Phusion Passenger does not need any further configurations.
Nevertheless, the system administrator may be interested in changing
Phusion Passenger's behavior. Phusion Passenger supports the following configuration
options in the Nginx configuration file:
=== passenger_root <directory> ===
The location to the Phusion Passenger root directory. This configuration option
is essential to Phusion Passenger, and allows Phusion Passenger to locate its own
data files. The correct value is given by the installer.
If you've moved Phusion Passenger to a different directory then you need to update
this option as well. Please read
<<moving_phusion_passenger,Moving Phusion Passenger to a different directory>> for more information.
This required option may only occur once, in the 'http' configuration block.
=== passenger_ruby <filename> ===
This option allows one to specify the Ruby interpreter to use.
This option may only occur once, in the 'http' configuration block.
The default is 'ruby'.
[[PassengerSpawnMethod]]
=== passenger_spawn_method <string> ===
[TIP]
."What spawn method should I use?"
=========================================================
This subsection attempts to describe spawn methods, but it's okay if you don't (want to)
understand it, as it's mostly a technical detail. You can basically follow this rule of thumb:
************************************************
If your application works on Mongrel, but not on Phusion Passenger, then set
`passenger_spawn_method` to 'conservative'. Otherwise, leave it at 'smart-lv2' (the default).
************************************************
However, we do recommend you to try to understand it. The 'smart' and 'smart-lv2' spawn
methods bring many benefits.
=========================================================
include::users_guide_snippets/passenger_spawn_method.txt[]
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'smart-lv2'.
[[PassengerRollingRestarts]]
=== passenger_rolling_restarts <on|off> ===
:version: 3.0.0
include::users_guide_snippets/enterprise_only.txt[]
Enables or disables support for rolling restarts. Normally when you
restart an application (by touching restart.txt), Phusion Passenger would
shut down all application processes and spawn a new one. The spawning
of a new application process could take a while, and any requests that
come in during this time will be blocked until this first application
process has spawned.
But when rolling restarts are enabled, Phusion Passenger Enterprise will:
1. Spawn a new process in the background.
2. When it's done spawning, Phusion Passenger Enterprise will replace one of the old processes with this newly spawned one.
3. Step 1 and 2 are repeated until all processes have been replaced.
This way, visitors will not experience any delays when you are restarting your application. This allows you to, for example, upgrade your application often without degrading user experience.
Rolling restarts have a few caveat however that you should be aware of:
- Upgrading an application sometimes involves upgrading the database schema.
With rolling restarts, there may be a point in time during which processes
belonging to the previous version and processes belonging to the new version
both exist at the same time. Any database schema upgrades you perform must
therefore be backwards-compatible with the old application version.
- Because there's no telling which process will serve a request, users may
not see changes brought about by the new version until all processes have
been restarted. It is for this reason that you should not use rolling
restarts in development, only in production.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'off'.
=== passenger_resist_deployment_errors <on|off> ===
:version: 3.0.0
include::users_guide_snippets/enterprise_only.txt[]
Enables or disables resistance against deployment errors.
Suppose you've upgraded your application and you've issues a command to restart it (by touching restart.txt), but the application code contains an error that prevents Phusion Passenger from successfully spawning a process (e.g. a syntax error). Phusion Passenger would normally display an error message in response to this.
By enabling deployment error resistance, Phusion Passenger Enterprise would instead do this:
- It passes the request to one of the existing application processes (that belong to the previous version of the application). The visitor will not see a Phusion Passenger process spawning error message.
- It logs the error to the global web server error log file.
- It sets an internal flag so that no processes for this application will be spawned (even when the current traffic would normally result in more processes being spawned) and no processes will be idle cleaned. Processes *could* still be shutdown because of other events, e.g. because their <<PassengerMemoryLimit,memory limit>> have been reached.
This way, visitors will suffer minimally from deployment errors. Phusion Passenger will attempt to restart the application again next time restart.txt is touched.
Enabling deployment error resistance only works if <<PassengerRollingRestarts,rolling restart>> is also enabled.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'off'.
=== Important deployment options ===
==== passenger_enabled <on|off> ====
This option may be specified in the 'http' configuration block, a
'server' configuration block, a 'location' configuration block or
an 'if' configuration scope, to enable or disable Phusion Passenger
for that server or that location.
Phusion Passenger is disabled by default, so you must explicitly enable
it for server blocks that you wish to serve through Phusion Passenger.
Please see <<deploying_a_ror_app,Deploying a Ruby on Rails application>>
and <<deploying_a_rack_app,Deploying a Rack-based Ruby application>>
for examples.
[[PassengerBaseURI]]
==== passenger_base_uri <uri> ====
Used to specify that the given URI is an distinct application that should
be served by Phusion Passenger. This option can be used for both Rails and
Rack applications. See <<deploying_rails_to_sub_uri,Deploying Rails to a sub URI>>
for an example.
It is allowed to specify this option multiple times. Do this to deploy multiple
applications in different sub-URIs under the same virtual host.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
=== Connection handling options ===
[[PassengerUseGlobalQueue]]
==== passenger_use_global_queue <on|off> ====
Turns the use of global queuing on or off.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'on'.
'This feature is sponsored by http://www.37signals.com/[37signals].'
include::users_guide_snippets/global_queueing_explained.txt[]
==== passenger_ignore_client_abort <on|off> ====
Normally, when the HTTP client aborts the connection (e.g. when the user clicked on "Stop"
in the browser), the connection with the application process will be closed too. If the
application process continues to send its response, then that will result in EPIPE errors
in the application, which will be printed in the error log if the application doesn't
handle them gracefully.
If this option is turned on then upon client abort Phusion Passenger will continue to
read the application process's response while discarding all the read data. This prevents
EPIPE errors but it'll also mean the backend process will be unavailable for new requests
until it is done sending its response.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'off'.
==== passenger_set_cgi_param <CGI environment name> <value> ====
Allows one to define additional CGI environment variables to pass to the backend
application. This is equivalent to ngx_http_fastcgi_module's 'fastcgi_param'
directive, and is comparable to ngx_http_proxy_module's 'proxy_set_header' option.
Nginx variables in the value are interpolated.
For example:
------------------------------
# Application will see a CGI environment "APP_NAME" with value "my super blog".
passenger_set_cgi_param APP_NAME "my super blog";
# Nginx variables are interpolated.
passenger_set_cgi_param EXTRA_REQUEST_METHOD method=$request_method;
------------------------------
If you want to set an HTTP header, then you must set it in the CGI environment name
format, i.e. 'HTTP_*':
------------------------------
# !!!THIS IS WRONG!!! Don't do this!
passenger_set_cgi_param X-Forwarded-For 127.0.0.2;
# Instead, write it like this:
passenger_set_cgi_param HTTP_X_FORWARDED_FOR 127.0.0.2;
------------------------------
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
==== passenger_pass_header <header name> ====
Some headers generated by backend applications are not forwarded to the HTTP client,
e.g. 'X-Accel-Redirect' which is directly processed by Nginx and then discarded from
the final response. This directive allows one to force Nginx to pass those headers
anyway, similar to how 'proxy_pass_header' works.
For example:
------------------------------
location / {
passenger_pass_header X-Accel-Redirect;
}
------------------------------
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
==== passenger_buffer_response <on|off> ====
When turned on, application-generated responses are buffered in memory and also on
disk if the response is larger than a certain threshold. By buffering responses,
protection is provided against slow HTTP clients that can not read your response
immediately.
For example, consider an HTTP client that's on a dial-up modem link, and your
application process generates a 2 MB response. If response buffering is turned
off then your application process will be blocked until the entire 2 MB has been
sent out to the HTTP client. This disallows your application process to do any useful
work in the mean time. By enabling response buffering, Phusion Passenger will read
the application response as quickly as possible and will take care of slow clients.
However, keep in mind that enabling this option will make streaming responses
impossible. Consider for example this piece of Rails code:
--------------------------------
render :text => lambda { |response, output|
10.times do |i|
output.write("entry #{i}\n")
output.flush
sleep 1
end
}
--------------------------------
...or this piece of Rack code:
--------------------------------
class Response
def each
10.times do |i|
yield("entry #{i}\n")
sleep 1
end
end
end
app = lambda do |env|
[200, { "Content-Type" => "text/plain" }, Response.new]
end
--------------------------------
When response buffering is turned on, Phusion Passenger will wait until
the application is done sending the entire response before forwarding it
to the client. The client will not receive anything for 10 seconds,
after which it receives the entire response at once.
When response buffering is turned off, it works as expected: the client
receives an "entry X" message every second for 10 seconds.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'on'.
==== passenger_buffer_size ====
==== passenger_buffers ====
==== passenger_busy_buffer_size ====
These options have the same effect as proxy_module's similarly named options.
They can be used to modify the maximum allowed HTTP header size.
=== Security options ===
[[PassengerUserSwitching]]
==== passenger_user_switching <on|off> ====
Whether to enable <<user_switching,user switching support>>.
This option may only occur once, in the 'http' configuration block.
The default value is 'on'.
==== passenger_user <username> ====
If <<user_switching,user switching support>> is enabled, then Phusion Passenger will
by default run the web application as the owner of the file 'config/environment.rb'
(for Rails apps) or 'config.ru' (for Rack apps). This option allows you to override
that behavior and explicitly set a user to run the web application as, regardless
of the ownership of 'environment.rb'/'config.ru'.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once.
==== passenger_group <group name> ====
If <<user_switching,user switching support>> is enabled, then Phusion Passenger will
by default run the web application as the primary group of the owner of the file
'config/environment.rb' (for Rails apps) or 'config.ru' (for Rack apps). This option
allows you to override that behavior and explicitly set a group to run the web application
as, regardless of the ownership of 'environment.rb'/'config.ru'.
'<group name>' may also be set to the special value '!STARTUP_FILE!', in which case
the web application's group will be set to 'environment.rb'/'config.ru''s group.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once.
[[PassengerDefaultUser]]
==== passenger_default_user <username> ====
Phusion Passenger enables <<user_switching,user switching support>> by default.
This configuration option allows one to specify the user that applications must
run as, if user switching fails or is disabled.
This option may only occur once, in the 'http' configuration block.
The default value is 'nobody'.
[[PassengerDefaultGroup]]
==== Passenger_default_group <group name> ====
Phusion Passenger enables <<user_switching,user switching support>> by default.
This configuration option allows one to specify the group that applications must
run as, if user switching fails or is disabled.
This option may only occur once, in the 'http' configuration block.
The default value is the primary group of the user specifified by
<<PassengerDefaultUser,passenger_default_user>>.
==== passenger_friendly_error_pages <on|off> ====
Phusion Passenger can display friendly error pages whenever an application fails
to start. This friendly error page presents the startup error message, some
suggestions for solving the problem, and a backtrace. This feature is very useful
during application development and useful for less experienced system administrators,
but the page might reveal potentially sensitive information, depending on the
application. Experienced system administrators who are using Phusion Passenger
on serious production servers should consider turning this feature off.
This option may occur in the following places:
* In the 'http' configuration block.
* In a 'server' configuration block.
* In a 'location' configuration block.
* In an 'if' configuration scope.
In each place, it may be specified at most once. The default value is 'on'.
=== Resource control and optimization options ===
[[PassengerMaxPoolSize]]
==== passenger_max_pool_size <integer> ====
The maximum number of <<application_process,application processes>> that may
simultanously exist. A larger number results in higher memory usage,
but improved ability to handle concurrent HTTP clients.
The optimal value depends on your system's hardware and the server's average
load. You should experiment with different values. But generally speaking,
the value should be at least equal to the number of CPUs (or CPU cores) that
you have. If your system has 2 GB of RAM, then we recommend a value of '15'.
If your system is a Virtual Private Server (VPS) and has about 256 MB RAM, and
is also running other services such as MySQL, then we recommend a value of '2'.
If you find that your server is unable to handle the load on your Rails/Rack websites
(i.e. running out of memory) then you should lower this value. (Though if your
sites are really that popular, then you should strongly consider upgrading your
hardware or getting more servers.)