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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="AsciiDoc 8.5.2" />
<title>Phusion Passenger users guide, Nginx version</title>
<style type="text/css">
/* Debug borders */
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
/*
border: 1px solid red;
*/
}
body {
margin: 1em 5% 1em 5%;
}
a {
color: blue;
text-decoration: underline;
}
a:visited {
color: fuchsia;
}
em {
font-style: italic;
color: navy;
}
strong {
font-weight: bold;
color: #083194;
}
tt {
color: navy;
}
h1, h2, h3, h4, h5, h6 {
color: #527bbd;
font-family: sans-serif;
margin-top: 1.2em;
margin-bottom: 0.5em;
line-height: 1.3;
}
h1, h2, h3 {
border-bottom: 2px solid silver;
}
h2 {
padding-top: 0.5em;
}
h3 {
float: left;
}
h3 + * {
clear: left;
}
div.sectionbody {
font-family: serif;
margin-left: 0;
}
hr {
border: 1px solid silver;
}
p {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
ul, ol, li > p {
margin-top: 0;
}
pre {
padding: 0;
margin: 0;
}
span#author {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
font-size: 1.1em;
}
span#email {
}
span#revnumber, span#revdate, span#revremark {
font-family: sans-serif;
}
div#footer {
font-family: sans-serif;
font-size: small;
border-top: 2px solid silver;
padding-top: 0.5em;
margin-top: 4.0em;
}
div#footer-text {
float: left;
padding-bottom: 0.5em;
}
div#footer-badges {
float: right;
padding-bottom: 0.5em;
}
div#preamble {
margin-top: 1.5em;
margin-bottom: 1.5em;
}
div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
div.admonitionblock {
margin-top: 1.0em;
margin-bottom: 1.5em;
}
div.admonitionblock {
margin-top: 2.0em;
margin-bottom: 2.0em;
margin-right: 10%;
color: #606060;
}
div.content { /* Block element content. */
padding: 0;
}
/* Block element titles. */
div.title, caption.title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
text-align: left;
margin-top: 1.0em;
margin-bottom: 0.5em;
}
div.title + * {
margin-top: 0;
}
td div.title:first-child {
margin-top: 0.0em;
}
div.content div.title:first-child {
margin-top: 0.0em;
}
div.content + div.title {
margin-top: 0.0em;
}
div.sidebarblock > div.content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.listingblock > div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock, div.verseblock {
padding-left: 1.0em;
margin-left: 1.0em;
margin-right: 10%;
border-left: 5px solid #dddddd;
color: #777777;
}
div.quoteblock > div.attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock > div.content {
white-space: pre;
}
div.verseblock > div.attribution {
padding-top: 0.75em;
text-align: left;
}
/* DEPRECATED: Pre version 8.2.7 verse style literal block. */
div.verseblock + div.attribution {
text-align: left;
}
div.admonitionblock .icon {
vertical-align: top;
font-size: 1.1em;
font-weight: bold;
text-decoration: underline;
color: #527bbd;
padding-right: 0.5em;
}
div.admonitionblock td.content {
padding-left: 0.5em;
border-left: 3px solid #dddddd;
}
div.exampleblock > div.content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
div.imageblock div.content { padding-left: 0; }
span.image img { border-style: none; }
a.image:visited { color: white; }
dl {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
dt {
margin-top: 0.5em;
margin-bottom: 0;
font-style: normal;
color: navy;
}
dd > *:first-child {
margin-top: 0.1em;
}
ul, ol {
list-style-position: outside;
}
ol.arabic {
list-style-type: decimal;
}
ol.loweralpha {
list-style-type: lower-alpha;
}
ol.upperalpha {
list-style-type: upper-alpha;
}
ol.lowerroman {
list-style-type: lower-roman;
}
ol.upperroman {
list-style-type: upper-roman;
}
div.compact ul, div.compact ol,
div.compact p, div.compact p,
div.compact div, div.compact div {
margin-top: 0.1em;
margin-bottom: 0.1em;
}
div.tableblock > table {
border: 3px solid #527bbd;
}
thead, p.table.header {
font-family: sans-serif;
font-weight: bold;
}
tfoot {
font-weight: bold;
}
td > div.verse {
white-space: pre;
}
p.table {
margin-top: 0;
}
/* Because the table frame attribute is overriden by CSS in most browsers. */
div.tableblock > table[frame="void"] {
border-style: none;
}
div.tableblock > table[frame="hsides"] {
border-left-style: none;
border-right-style: none;
}
div.tableblock > table[frame="vsides"] {
border-top-style: none;
border-bottom-style: none;
}
div.hdlist {
margin-top: 0.8em;
margin-bottom: 0.8em;
}
div.hdlist tr {
padding-bottom: 15px;
}
dt.hdlist1.strong, td.hdlist1.strong {
font-weight: bold;
}
td.hdlist1 {
vertical-align: top;
font-style: normal;
padding-right: 0.8em;
color: navy;
}
td.hdlist2 {
vertical-align: top;
}
div.hdlist.compact tr {
margin: 0;
padding-bottom: 0;
}
.comment {
background: yellow;
}
.footnote, .footnoteref {
font-size: 0.8em;
}
span.footnote, span.footnoteref {
vertical-align: super;
}
#footnotes {
margin: 20px 0 20px 0;
padding: 7px 0 0 0;
}
#footnotes div.footnote {
margin: 0 0 5px 0;
}
#footnotes hr {
border: none;
border-top: 1px solid silver;
height: 1px;
text-align: left;
margin-left: 0;
width: 20%;
min-width: 100px;
}
@media print {
div#footer-badges { display: none; }
}
div#toc {
margin-bottom: 2.5em;
}
div#toctitle {
color: #527bbd;
font-family: sans-serif;
font-size: 1.1em;
font-weight: bold;
margin-top: 1.0em;
margin-bottom: 0.1em;
}
div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
margin-top: 0;
margin-bottom: 0;
}
div.toclevel2 {
margin-left: 2em;
font-size: 0.9em;
}
div.toclevel3 {
margin-left: 4em;
font-size: 0.9em;
}
div.toclevel4 {
margin-left: 6em;
font-size: 0.9em;
}
/* Workarounds for IE6's broken and incomplete CSS2. */
div.sidebar-content {
background: #ffffee;
border: 1px solid silver;
padding: 0.5em;
}
div.sidebar-title, div.image-title {
color: #527bbd;
font-family: sans-serif;
font-weight: bold;
margin-top: 0.0em;
margin-bottom: 0.5em;
}
div.listingblock div.content {
border: 1px solid silver;
background: #f4f4f4;
padding: 0.5em;
}
div.quoteblock-attribution {
padding-top: 0.5em;
text-align: right;
}
div.verseblock-content {
white-space: pre;
}
div.verseblock-attribution {
padding-top: 0.75em;
text-align: left;
}
div.exampleblock-content {
border-left: 3px solid #dddddd;
padding-left: 0.5em;
}
/* IE6 sets dynamically generated links as visited. */
div#toc a:visited { color: blue; }
</style>
<script type="text/javascript">
/*<+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
var iterate = function (el) {
for (var i = el.firstChild; i != null; i = i.nextSibling) {
if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
var mo = re.exec(i.tagName);
if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
}
iterate(i);
}
}
}
iterate(el);
return result;
}
var toc = document.getElementById("toc");
var entries = tocEntries(document.getElementById("content"), toclevels);
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
if (entry.element.id == "")
entry.element.id = "_toc_" + i;
var a = document.createElement("a");
a.href = "#" + entry.element.id;
a.appendChild(document.createTextNode(entry.text));
var div = document.createElement("div");
div.appendChild(a);
div.className = "toclevel" + entry.toclevel;
toc.appendChild(div);
}
if (entries.length == 0)
toc.parentNode.removeChild(toc);
},
/////////////////////////////////////////////////////////////////////
// Footnotes generator
/////////////////////////////////////////////////////////////////////
/* Based on footnote generation code from:
* http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
*/
footnotes: function () {
var cont = document.getElementById("content");
var noteholder = document.getElementById("footnotes");
var spans = cont.getElementsByTagName("span");
var refs = {};
var n = 0;
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnote") {
n++;
// Use [\s\S] in place of . so multi-line matches work.
// Because JavaScript has no s (dotall) regex flag.
note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
noteholder.innerHTML +=
"<div class='footnote' id='_footnote_" + n + "'>" +
"<a href='#_footnoteref_" + n + "' title='Return to text'>" +
n + "</a>. " + note + "</div>";
spans[i].innerHTML =
"[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
var id =spans[i].getAttribute("id");
if (id != null) refs["#"+id] = n;
}
}
if (n == 0)
noteholder.parentNode.removeChild(noteholder);
else {
// Process footnoterefs.
for (i=0; i<spans.length; i++) {
if (spans[i].className == "footnoteref") {
var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
href = href.match(/#.*/)[0]; // Because IE return full URL.
n = refs[href];
spans[i].innerHTML =
"[<a href='#_footnote_" + n +
"' title='View footnote' class='footnote'>" + n + "</a>]";
}
}
}
}
}
/*]]>*/
</script>
</head>
<body>
<div id="header">
<h1>Phusion Passenger users guide, Nginx version</h1>
<div id="toc">
<div id="toctitle">Table of Contents</div>
<noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
</a>
</span></p></div>
<div class="paragraph"><p>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.</p></div>
<div class="paragraph"><p>This users guide will teach you:</p></div>
<div class="ulist"><ul>
<li>
<p>
How to install Nginx with Phusion Passenger support.
</p>
</li>
<li>
<p>
How to configure Phusion Passenger.
</p>
</li>
<li>
<p>
How to deploy a Ruby on Rails application.
</p>
</li>
<li>
<p>
How to deploy a <a href="http://rack.rubyforge.org/">Rack</a>-based Ruby application.
</p>
</li>
<li>
<p>
How to solve common problems.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This guide assumes that the reader is somewhat familiar with Nginx and with
using the commandline.</p></div>
</div>
</div>
<h2 id="_supported_operating_systems">1. Supported operating systems</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger works on any POSIX-compliant operating system. In other
words: practically any operating system on earth, except Microsoft Windows.</p></div>
<div class="paragraph"><p>Phusion Passenger for Nginx has been tested on:</p></div>
<div class="ulist"><ul>
<li>
<p>
Ubuntu Linux 8.04 (x86)
</p>
</li>
<li>
<p>
Gentoo Linux (AMD64)
</p>
</li>
<li>
<p>
MacOS X Leopard (x86)
</p>
</li>
</ul></div>
<div class="paragraph"><p>Other operating systems have not been tested, but Phusion Passenger will probably
work fine on them. Please
<a href="http://code.google.com/p/phusion-passenger/issues/list">report a bug</a>
or
<a href="http://groups.google.com/group/phusion-passenger">join our discussion list</a>
if it doesn’t.</p></div>
</div>
<h2 id="install_passenger">2. Installing Phusion Passenger</h2>
<div class="sectionbody">
<h3 id="_overview">2.1. Overview</h3><div style="clear:left"></div>
<div class="paragraph"><p>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:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
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.
</p>
</li>
<li>
<p>
By manually configuring and compiling Nginx with Phusion Passenger support,
through Nginx’s <tt>--add-module</tt> configure option. Generally, using our
installer is easier, so you should only use this method if you’re already
familiar with compiling Nginx.
</p>
</li>
</ol></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">You might have to run the installation commands in the following sections
as <em>root</em>. If the installer fails because of permission errors, it will tell
you.</td>
</tr></table>
</div>
<h3 id="specifying_ruby_installation">2.2. Specifying the correct Ruby installation</h3><div style="clear:left"></div>
<div class="paragraph"><p>If your system has multiple Ruby installations — which is likely the case on
MacOS X, or if you’ve also installed
<a href="http://www.rubyenterpriseedition.com">Ruby Enterprise Edition</a> — 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.</p></div>
<div class="paragraph"><p>To specify a Ruby installation, prepend your Ruby installation’s <tt>bin</tt>
directory to the <tt>PATH</tt> environment variable. For example, if you have the
following Ruby installations:</p></div>
<div class="ulist"><ul>
<li>
<p>
/usr/bin/ruby
</p>
</li>
<li>
<p>
/opt/myruby/bin/ruby
</p>
</li>
</ul></div>
<div class="paragraph"><p>and you want to use the latter, then type:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>export PATH=/opt/myruby/bin:$PATH</tt></pre>
</div></div>
<h3 id="_installing_phusion_passenger_for_nginx_through_the_installer">2.3. Installing Phusion Passenger for Nginx through the installer</h3><div style="clear:left"></div>
<h4 id="_obtaining_the_phusion_passenger_files_and_running_the_installer">2.3.1. Obtaining the Phusion Passenger files and running the installer</h4>
<div class="paragraph"><p>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.</p></div>
<h5 id="_gem">Gem</h5>
<div class="paragraph"><p>First, install the Phusion Passenger gem by running:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>gem install passenger</tt></pre>
</div></div>
<div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>passenger-install-nginx-module</tt></pre>
</div></div>
<div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
<h5 id="_source_tarball">Source tarball</h5>
<div class="paragraph"><p>The source tarball can be download from the
<a href="http://www.modrails.com/">Phusion Passenger website</a>. Extract the tarball to
whatever location you prefer. <strong>The Phusion Passenger files are to reside in that
location permanently.</strong> For example, if you would like Phusion Passenger to
reside in <tt>/opt/passenger-x.x.x</tt>, then type:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>cd /opt
tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz</tt></pre>
</div></div>
<div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/opt/passenger-x.x.x/bin/passenger-install-nginx-module</tt></pre>
</div></div>
<div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/important.png" alt="Important" />
</td>
<td class="content">Please do not remove the passenger-x.x.x folder after installation.
Furthermore, the passenger-x.x.x folder must be accessible by Nginx.</td>
</tr></table>
</div>
<h4 id="_non_interactive_automatic_installation">2.3.2. Non-interactive/automatic installation</h4>
<div class="paragraph"><p>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.</p></div>
<div class="paragraph"><p>Please run the installer with <tt>--help</tt> for a list of available command line
options.</p></div>
<h3 id="_installing_phusion_passenger_for_nginx_manually">2.4. Installing Phusion Passenger for Nginx manually</h3><div style="clear:left"></div>
<div class="paragraph"><p>You can also install Phusion Passenger the way you install any other Nginx module.
To do this, run Nginx’s configure script with <tt>--add-module=/path-to-passenger-root/ext/nginx</tt>.</p></div>
<div class="paragraph"><p>If you installed Phusion Passenger via the gem, then <em>path-to-passenger-root</em>
can be obtained with the command:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>passenger-config --root</tt></pre>
</div></div>
<div class="paragraph"><p>This will probably output something along the lines of <em>/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x</em>,
so you’ll probably have to specify something like <tt>--add-module=/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x/ext/nginx</tt>.</p></div>
<div class="paragraph"><p>If you installed Phusion Passenger via a source tarball, then <em>path-to-passenger-root</em>
is the directory which contains the Phusion Passenger source code. So if you
extracted the Phusion Passenger source code to <em>/opt/passenger-x.x.x</em>, then you’ll
have to specify <tt>--add-module=/opt/passenger-x.x.x/ext/nginx</tt>.</p></div>
</div>
<h2 id="deploying_a_ror_app">3. Deploying a Ruby on Rails application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Suppose you have a Ruby on Rails application in <em>/webapps/mycook</em>, and you own
the domain <em>www.mycook.com</em>. You can either deploy your application to the
virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.mycook.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.mycook.com/railsapplication</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">The default <tt>RAILS_ENV</tt> environment in which deployed Rails applications
are run, is “production”. You can change this by changing the
<a href="#RailsEnv">rails_env</a> configuration option.</td>
</tr></table>
</div>
<h3 id="_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host’s root</h3><div style="clear:left"></div>
<div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual
host’s root must point to your Ruby on Rails application’s <em>public</em> folder.</p></div>
<div class="paragraph"><p>Inside the <em>server</em> block, set <em>passenger_enabled on</em>.</p></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.mycook.com;
root /webapps/mycook/public;
passenger_enabled on;
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
<h3 id="deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</h3><div style="clear:left"></div>
<div class="paragraph"><p>Suppose that you already have a <em>server</em> virtual host entry:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>And you want your Ruby on Rails application to be accessible from the URL
<em>http://www.phusion.nl/rails</em>.</p></div>
<div class="paragraph"><p>To do this, make a symlink from your Ruby on Rails application’s <em>public</em>
folder to a directory in the document root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>ln -s /webapps/mycook/public /websites/phusion/rails</tt></pre>
</div></div>
<div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#PassengerBaseURI">passenger_base_uri</a>
option to the <em>server</em> block:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rails; # <--- been added.
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="paragraph"><p>You can deploy multiple Rails applications under a virtual host, by specifying
<a href="#PassengerBaseURI">passenger_base_uri</a> multiple times. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>server {
...
passenger_base_uri /app1;
passenger_base_uri /app2;
passenger_base_uri /app3;
}</tt></pre>
</div></div>
</td>
</tr></table>
</div>
<h3 id="_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</h3><div style="clear:left"></div>
<div class="paragraph"><p>Deploying a new version of a Ruby on Rails application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Nginx.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rails
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application during the next request.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example MyCook application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>touch /webapps/mycook/tmp/restart.txt</tt></pre>
</div></div>
<div class="paragraph"><p>Please note that, unlike earlier versions of Phusion Passenger, <em>restart.txt</em>
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.</p></div>
<h3 id="_migrations">3.4. Migrations</h3><div style="clear:left"></div>
<div class="paragraph"><p>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 <em>ssh</em>) and type <tt>rake db:migrate RAILS_ENV=production</tt> in
a shell console, just like one would normally run migrations.</p></div>
<h3 id="_capistrano_integration">3.5. Capistrano integration</h3><div style="clear:left"></div>
<div class="paragraph"><p>See <a href="#capistrano">Capistrano recipe</a>.</p></div>
</div>
<h2 id="deploying_a_rack_app">4. Deploying a Rack-based Ruby application</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger supports arbitrary Ruby web applications that follow the
<a href="http://rack.rubyforge.org/">Rack</a> interface.</p></div>
<div class="paragraph"><p>Phusion Passenger assumes that Rack application directories have a certain layout.
Suppose that you have a Rack application in <em>/webapps/rackapp</em>. Then that
folder must contain at least three entries:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>config.ru</em>, a Rackup file for starting the Rack application. This file must contain
the complete logic for initializing the application.
</p>
</li>
<li>
<p>
<em>public/</em>, a folder containing public static web assets, like images and stylesheets.
</p>
</li>
<li>
<p>
<em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will
be explained in a following subsection.
</p>
</li>
</ul></div>
<div class="paragraph"><p>So <em>/webapps/rackapp</em> must, at minimum, look like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/webapps/rackapp
|
+-- config.ru
|
+-- public/
|
+-- tmp/</tt></pre>
</div></div>
<div class="paragraph"><p>Suppose you own the domain <em>www.rackapp.com</em>. You can either deploy your application
to the virtual host’s root (i.e. the application will be accessible from the root URL,
<em>http://www.rackapp.com/</em>), or in a sub URI (i.e. the application will be
accessible from a sub URL, such as <em>http://www.rackapp.com/rackapp</em>).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">The default <tt>RACK_ENV</tt> environment in which deployed Rack applications
are run, is “production”. You can change this by changing the
<a href="#RackEnv">rack_env</a> configuration option.</td>
</tr></table>
</div>
<h3 id="_tutorial_example_writing_and_deploying_a_hello_world_rack_application">4.1. Tutorial/example: writing and deploying a Hello World Rack application</h3><div style="clear:left"></div>
<div class="paragraph"><p>First we create a Phusion Passenger-compliant Rack directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ mkdir /webapps/rack_example
$ mkdir /webapps/rack_example/public
$ mkdir /webapps/rack_example/tmp</tt></pre>
</div></div>
<div class="paragraph"><p>Next, we write a minimal "hello world" Rack application:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>$ 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</tt></pre>
</div></div>
<div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
the Apache configuration file:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.rackexample.com;
root /webapps/rack_example/public;
passenger_enabled on;
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>And we’re done! After an Nginx restart, the above Rack application will be available
under the URL <em>http://www.rackexample.com/</em>.</p></div>
<h3 id="_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host’s root</h3><div style="clear:left"></div>
<div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual host’s
root must point to your Rack application’s <em>public</em> folder. You must also set
<em>passenger_enabled on</em> in the <em>server</em> block.</p></div>
<div class="paragraph"><p>For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.rackapp.com;
root /webapps/rackapp/public;
passenger_enabled on;
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
<h3 id="deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</h3><div style="clear:left"></div>
<div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on;
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>And you want your Rack application to be accessible from the URL
<em>http://www.phusion.nl/rack</em>.</p></div>
<div class="paragraph"><p>To do this, make a symlink from your Rack application’s <em>public</em>
folder to a directory in the document root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>ln -s /webapps/rackapp/public /websites/phusion/rack</tt></pre>
</div></div>
<div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#PassengerBaseURI">passenger_base_uri</a>
option to the <em>server</em> block:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>http {
...
server {
listen 80;
server_name www.phusion.nl;
root /websites/phusion;
passenger_enabled on; # <--- These lines have
passenger_base_uri /rack; # <--- been added.
}
...
}</tt></pre>
</div></div>
<div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="paragraph"><p>You can deploy multiple Rack applications under a virtual host, by specifying
<a href="#PassengerBaseURI">passenger_base_uri</a> multiple times. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>server {
...
passenger_base_uri /app1;
passenger_base_uri /app2;
passenger_base_uri /app3;
}</tt></pre>
</div></div>
</td>
</tr></table>
</div>
<h3 id="_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</h3><div style="clear:left"></div>
<div class="paragraph"><p>Deploying a new version of a Rack application is as simple as
re-uploading the application files, and restarting the application.</p></div>
<div class="paragraph"><p>There are two ways to restart the application:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
By restarting Nginx.
</p>
</li>
<li>
<p>
By creating or modifying the file <em>tmp/restart.txt</em> in the Rack
application’s <a href="#application_root">root folder</a>. Phusion Passenger will
automatically restart the application.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, to restart our example application, we type this in the
command line:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>touch /webapps/rackapp/tmp/restart.txt</tt></pre>
</div></div>
<h3 id="_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</h3><div style="clear:left"></div>
<div class="paragraph"><p>This subsection shows example <em>config.ru</em> files for various web frameworks.</p></div>
<h4 id="_camping">4.5.1. Camping</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'rack'
require 'camping'
##### Begin Camping application
Camping.goes :Blog
...your application code here...
##### End Camping application
run Rack::Adapter::Camping.new(Blog)</tt></pre>
</div></div>
<div class="paragraph"><p>For Camping versions 2.0 and up, using <tt>run Blog</tt> as the final line will do.</p></div>
<h4 id="_halcyon">4.5.2. Halcyon</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'halcyon'
$LOAD_PATH.unshift(Halcyon.root / 'lib')
Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
run Halcyon::Runner.new</tt></pre>
</div></div>
<h4 id="_mack">4.5.3. Mack</h4>
<div class="listingblock">
<div class="content">
<pre><tt>ENV["MACK_ENV"] = ENV["RACK_ENV"]
load("Rakefile")
require 'rubygems'
require 'mack'
run Mack::Utils::Server.build_app</tt></pre>
</div></div>
<h4 id="_merb">4.5.4. Merb</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'merb-core'
Merb::Config.setup(
:merb_root => ::File.expand_path(::File.dirname(__FILE__)),
:environment => ENV['RACK_ENV']
)
Merb.environment = Merb::Config[:environment]
Merb.root = Merb::Config[:merb_root]
Merb::BootLoader.run
run Merb::Rack::Application.new</tt></pre>
</div></div>
<h4 id="_ramaze">4.5.5. Ramaze</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require "rubygems"
require "ramaze"
Ramaze.trait[:essentials].delete Ramaze::Adapter
require "start"
Ramaze.start!
run Ramaze::Adapter::Base</tt></pre>
</div></div>
<h4 id="_sinatra">4.5.6. Sinatra</h4>
<div class="listingblock">
<div class="content">
<pre><tt>require 'rubygems'
require 'sinatra'
require 'app.rb'
run Sinatra::Application</tt></pre>
</div></div>
</div>
<h2 id="_configuring_phusion_passenger">5. Configuring Phusion Passenger</h2>
<div class="sectionbody">
<div class="paragraph"><p>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:</p></div>
<h3 id="_passenger_root_lt_directory_gt">5.1. passenger_root <directory></h3><div style="clear:left"></div>
<div class="paragraph"><p>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.</p></div>
<div class="paragraph"><p>If you’ve moved Phusion Passenger to a different directory then you need to update
this option as well. Please read
<a href="#moving_phusion_passenger">Moving Phusion Passenger to a different directory</a> for more information.</p></div>
<div class="paragraph"><p>This required option may only occur once, in the <em>http</em> configuration block.</p></div>
<h3 id="_passenger_log_level_lt_integer_gt">5.2. passenger_log_level <integer></h3><div style="clear:left"></div>
<div class="paragraph"><p>This option allows one to specify how much information Phusion Passenger should
write to the Apache error log file. A higher log level value means that more
information will be logged.</p></div>
<div class="paragraph"><p>Possible values are:</p></div>
<div class="ulist"><ul>
<li>
<p>
<em>0</em>: Show only errors and warnings.
</p>
</li>
<li>
<p>
<em>1</em>: Show the most important debugging information. This might be useful for
system administrators who are trying to figure out the cause of a
problem.
</p>
</li>
<li>
<p>
<em>2</em>: Show more debugging information. This is typically only useful for developers.
</p>
</li>
<li>
<p>
<em>3</em>: Show even more debugging information.
</p>
</li>
</ul></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default is <em>0</em>.</p></div>
<h3 id="_passenger_ruby_lt_filename_gt">5.3. passenger_ruby <filename></h3><div style="clear:left"></div>
<div class="paragraph"><p>This option allows one to specify the Ruby interpreter to use.</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default is <em>ruby</em>.</p></div>
<h3 id="PassengerUseGlobalQueue">5.4. passenger_use_global_queue <on|off></h3><div style="clear:left"></div>
<div class="paragraph"><p>Turns the use of global queuing on or off.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
<div class="paragraph"><p><em>This feature is sponsored by <a href="http://www.37signals.com/">37signals</a>.</em></p></div>
<div class="paragraph"><div class="title">What does this option do?</div><p>Recall that Phusion Passenger spawns multiple backend processes (e.g. multiple
Ruby on Rails processes), each which processes HTTP requests serially. One of
Phusion Passenger’s jobs is to forward HTTP requests to a suitable backend
process. A backend process may take an arbitrary amount of time to process a
specific HTTP request. If the websites are (temporarily) under high load, and
the backend processes cannot process the requests fast enough, then some
requests may have to be queued.</p></div>
<div class="paragraph"><p>If global queuing is turned off, then Phusion Passenger will use <em>fair load
balancing</em>. This means that each backend process will have its own private
queue. Phusion Passenger will forward an HTTP request to the backend process
that has the least amount of requests in its queue.</p></div>
<div class="paragraph"><p>If global queuing is turned on, then Phusion Passenger will use a global queue
that’s shared between all backend processes. If an HTTP request comes in, and
all the backend processes are still busy, then Phusion Passenger will wait until
at least one backend process is done, and will then forward the request to that
process.</p></div>
<div class="paragraph"><div class="title">When to turn on global queuing?</div><p>You should turn on global queuing if one of your web applications may have
long-running requests.</p></div>
<div class="paragraph"><p>For example suppose that:</p></div>
<div class="ulist"><ul>
<li>
<p>
global queuing is turned off.
</p>
</li>
<li>
<p>
we’re currently in a state where all backend processes have 3 requests in
their queue, except for a single backend process, which has 1 request in its
queue.
</p>
</li>
</ul></div>
<div class="paragraph"><p>The situation looks like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [* ] (1 request in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>Each process is currently serving short-running requests.</p></div>
<div class="paragraph"><p>Phusion Passenger will forward the next request to backend process A. A will
now have 2 items in its queue. We’ll mark this new request with an X:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [*X ] (2 request in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>Assuming that B, C and D still aren’t done with their current request, the next
HTTP request - let’s call this Y - will be forwarded to backend process A as
well, because it has the least number of items in its queue:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>Backend process A: [*XY ] (3 requests in queue)
Backend process B: [*** ] (3 requests in queue)
Backend process C: [*** ] (3 requests in queue)
Backend process D: [*** ] (3 requests in queue)</tt></pre>
</div></div>
<div class="paragraph"><p>But if request X happens to be a long-running request that needs 60 seconds to
complete, then we’ll have a problem. Y won’t be processed for at least 60
seconds. It would have been a better idea if Y was forward to processes B, C or
D instead, because they only have short-living requests in their queues.</p></div>
<div class="paragraph"><p>This problem will be avoided entirely if you turn global queuing on. With global
queuing, all backend processes will share the same queue. The first backend
process that becomes available will take from the queue, and so this
“queuing-behind-long-running-request” problem will never occur.</p></div>
<div class="paragraph"><p>Turning global queuing off will yield a minor performance improvement (about 5%,
depending on how fast/slow your web application is), which is why it’s off by
default.</p></div>
<h3 id="PassengerUserSwitching">5.5. passenger_user_switching <on|off></h3><div style="clear:left"></div>
<div class="paragraph"><p>Whether to enable <a href="#user_switching">user switching support</a>.</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default value is <em>on</em>.</p></div>
<h3 id="PassengerDefaultUser">5.6. passenger_default_user <username></h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger enables <a href="#user_switching">user switching support</a> by default.
This configuration option allows one to specify which user Rails/Rack
applications must run as, if user switching fails or is disabled.</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default value is <em>nobody</em>.</p></div>
<h3 id="_important_deployment_options">5.7. Important deployment options</h3><div style="clear:left"></div>
<h4 id="_passenger_enabled_lt_on_off_gt">5.7.1. passenger_enabled <on|off></h4>
<div class="paragraph"><p>This option may be specified in a <em>server</em> configuration block, a
<em>location</em> configuration block or an <em>if</em> configuration scope, to
enable or disable Phusion Passenger for that server or that location.</p></div>
<div class="paragraph"><p>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 <a href="#deploying_a_ror_app">Deploying a Ruby on Rails application</a>
and <a href="#deploying_a_rack_app">Deploying a Rack-based Ruby application</a>
for examples.</p></div>
<h4 id="PassengerBaseURI">5.7.2. passenger_base_uri <uri></h4>
<div class="paragraph"><p>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 <a href="#deploying_rails_to_sub_uri">Deploying Rails to a sub URI</a>
for an example.</p></div>
<div class="paragraph"><p>It is allowed to specify this option multiple times. Do this to deploy multiple
applications in different sub-URIs under the same virtual host.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<h3 id="_resource_control_and_optimization_options">5.8. Resource control and optimization options</h3><div style="clear:left"></div>
<h4 id="PassengerMaxPoolSize">5.8.1. passenger_max_pool_size <integer></h4>
<div class="paragraph"><p>The maximum number of Ruby on Rails or Rack application instances that may
be simultaneously active. A larger number results in higher memory usage,
but improved ability to handle concurrent HTTP clients.</p></div>
<div class="paragraph"><p>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 <em>30</em>.
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 <em>2</em>.</p></div>
<div class="paragraph"><p>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.)</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration bock.
The default value is <em>6</em>.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">We strongly recommend you to <a href="#reducing_memory_usage">use Ruby Enterprise Edition</a>. This allows you to reduce the memory usage of your Ruby on Rails applications
by about 33%. And it’s not hard to install.</td>
</tr></table>
</div>
<h4 id="_passenger_max_instances_per_app_lt_integer_gt">5.8.2. passenger_max_instances_per_app <integer></h4>
<div class="paragraph"><p>The maximum number of application instances that may be simultaneously active
for a single application. This helps to make sure that a single application
will not occupy all available slots in the application pool.</p></div>
<div class="paragraph"><p>This value must be less than <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a>. A value of 0
means that there is no limit placed on the number of instances a single application
may use, i.e. only the global limit of <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a>
will be enforced.</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default value is <em>0</em>.</p></div>
<h4 id="PassengerPoolIdleTime">5.8.3. passenger_pool_idle_time <integer></h4>
<div class="paragraph"><p>The maximum number of seconds that an application instance may be idle. That is,
if an application instance hasn’t received any traffic after the given number of
seconds, then it will be shutdown in order to conserve memory.</p></div>
<div class="paragraph"><p>Decreasing this value means that applications will have to be spawned
more often. Since spawning is a relatively slow operation, some visitors may
notice a small delay when they visit your Rails/Rack website. However, it will also
free up resources used by applications more quickly.</p></div>
<div class="paragraph"><p>The optimal value depends on the average time that a visitor spends on a single
Rails/Rack web page. We recommend a value of <tt>2 * x</tt>, where <tt>x</tt> is the average
number of seconds that a visitor spends on a single Rails/Rack web page. But your
mileage may vary.</p></div>
<div class="paragraph"><p>When this value is set to <em>0</em>, application instances will not be shutdown unless
it’s really necessary, i.e. when Phusion Passenger is out of worker processes
for a given application and one of the inactive application instances needs to
make place for another application instance. Setting the value to 0 is
recommended if you’re on a non-shared host that’s only running a few
applications, each which must be available at all times.</p></div>
<div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
The default value is <em>300</em>.</p></div>
<h3 id="_ruby_on_rails_specific_options">5.9. Ruby on Rails-specific options</h3><div style="clear:left"></div>
<h4 id="RailsEnv">5.9.1. rails_env <string></h4>
<div class="paragraph"><p>This option allows one to specify the default <tt>RAILS_ENV</tt> value.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
<h4 id="_rails_spawn_method_lt_string_gt">5.9.2. rails_spawn_method <string></h4>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/tip.png" alt="Tip" />
</td>
<td class="content">
<div class="title">"What spawn method should I use?"</div>
<div class="paragraph"><p>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:</p></div>
<div class="sidebarblock">
<div class="sidebar-content">
<div class="paragraph"><p>If your application works on Mongrel, but not on Phusion Passenger, then set
<tt>rails_spawn_method</tt> to <em>conservative</em>. Otherwise, leave it at <em>smart-lv2</em> (the default).</p></div>
</div></div>
<div class="paragraph"><p>However, we do recommend you to try to understand it. The <em>smart</em> and <em>smart-lv2</em> spawn
methods bring many benefits.</p></div>
</td>
</tr></table>
</div>
<div class="paragraph"><p>Internally, Phusion Passenger spawns multiple Ruby on Rails processes in order to handle
requests. But there are multiple ways with which processes can be spawned, each having
its own set of pros and cons. Supported spawn methods are:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
<em>smart</em>
</dt>
<dd>
<p>
When this spawn method is used, Phusion Passenger will attempt to cache Ruby on Rails
framework code and application code for a limited period of time. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what smart spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
This can significantly decrease spawn time (by as much as 90%). And, when Ruby Enterprise
Edition is used, <a href="#reducing_memory_usage">memory usage can be reduced by 33% on average</a>.</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
Some Ruby on Rails applications and libraries are not compatible with smart spawning.
If that’s the case for your application, then you should use <em>conservative</em> as
spawning method.</p></div>
</dd>
<dt class="hdlist1">
<em>smart-lv2</em>
</dt>
<dd>
<p>
This spawning method is similar to <em>smart</em> but it skips the framework spawner
and uses the application spawner directly. This means the framework code is not
cached between multiple applications, although it is still cached within
instances of the same application. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what smart-lv2 spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong> It is compatible with a larger number of applications when compared to
the <em>smart</em> method, and still performs some caching.</p></div>
<div class="paragraph"><p><strong>Cons:</strong> It is slower than smart spawning if you have many applications which
use the same framework version. It is therefore advised that shared hosts use the
<em>smart</em> method instead.</p></div>
</dd>
<dt class="hdlist1">
<em>conservative</em>
</dt>
<dd>
<p>
This spawning method is similar to the one used in Mongrel Cluster. It does not
perform any code caching at all. Please read
<a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
explanation of what conservative spawning exactly does.
</p>
<div class="paragraph"><p><strong>Pros:</strong>
Conservative spawning is guaranteed to be compatible with all Rails applications
and libraries.</p></div>
<div class="paragraph"><p><strong>Cons:</strong>
Much slower than smart spawning. Every spawn action will be equally slow, though no slower than
the startup time of a single server in Mongrel Cluster. Conservative spawning will also
render <a href="#reducing_memory_usage">Ruby Enterprise Edition’s memory reduction technology</a> useless.</p></div>
</dd>
</dl></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the <em>http</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>smart-lv2</em>.</p></div>
<h4 id="_rails_framework_spawner_idle_time_lt_integer_gt">5.9.3. rails_framework_spawner_idle_time <integer></h4>
<div class="paragraph"><p>The FrameworkSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
Phusion Passenger do. That is, it will automatically shutdown if it hasn’t done
anything for a given period.</p></div>
<div class="paragraph"><p>This option allows you to set the FrameworkSpawner server’s idle timeout, in
seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
<div class="paragraph"><p>Setting a higher value will mean that the FrameworkSpawner server is kept around
longer, which may slightly increase memory usage. But as long as the
FrameworkSpawner server is running, the time to spawn a Ruby on Rails backend
process only takes about 40% of the time that is normally needed, assuming that
you’re using the <em>smart</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
system has enough memory, is it recommended that you set this option to a high
value or to <em>0</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the <em>http</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>1800</em> (30 minutes).</p></div>
<h4 id="_rails_app_spawner_idle_time_lt_integer_gt">5.9.4. rails_app_spawner_idle_time <integer></h4>
<div class="paragraph"><p>The ApplicationSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
Phusion Passenger do. That is, it will automatically shutdown if it hasn’t done
anything for a given period.</p></div>
<div class="paragraph"><p>This option allows you to set the ApplicationSpawner server’s idle timeout, in
seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
<div class="paragraph"><p>Setting a higher value will mean that the ApplicationSpawner server is kept around
longer, which may slightly increase memory usage. But as long as the
ApplicationSpawner server is running, the time to spawn a Ruby on Rails backend
process only takes about 10% of the time that is normally needed, assuming that
you’re using the <em>smart</em> or <em>smart-lv2</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
system has enough memory, is it recommended that you set this option to a high
value or to <em>0</em>.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In the <em>http</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>600</em> (10 minutes).</p></div>
<h3 id="_rack_specific_options">5.10. Rack-specific options</h3><div style="clear:left"></div>
<h4 id="RackEnv">5.10.1. rack_env <string></h4>
<div class="paragraph"><p>This option allows one to specify the default <tt>RACK_ENV</tt> value.</p></div>
<div class="paragraph"><p>This option may occur in the following places:</p></div>
<div class="ulist"><ul>
<li>
<p>
In a <em>server</em> configuration block.
</p>
</li>
<li>
<p>
In a <em>location</em> configuration block.
</p>
</li>
<li>
<p>
In an <em>if</em> configuration scope.
</p>
</li>
</ul></div>
<div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
</div>
<h2 id="_analysis_and_system_maintenance_tools">6. Analysis and system maintenance tools</h2>
<div class="sectionbody">
<div class="paragraph"><p>Phusion Passenger provides a set of tools, which are useful for system analysis,
maintenance and troubleshooting.</p></div>
<h3 id="_inspecting_memory_usage">6.1. Inspecting memory usage</h3><div style="clear:left"></div>
<div class="paragraph"><p>Process inspection tools such as <tt>ps</tt> and <tt>top</tt> are useful, but they
<a href="http://groups.google.com/group/phusion-passenger/msg/1fd1c233456d3180">rarely show the correct memory usage</a>.
The real memory usage is usually lower than what <tt>ps</tt> and <tt>top</tt> report.</p></div>
<div class="paragraph"><p>There are many technical reasons why this is so, but an explanation is beyond
the scope of this Users Guide. We kindly refer the interested reader to
operating systems literature about <em>virtual memory</em> and <em>copy-on-write</em>.</p></div>
<div class="paragraph"><p>The tool <tt>passenger-memory-stats</tt> allows one to easily analyze Phusion Passenger’s
and Apache’s real memory usage. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[bash@localhost root]# passenger-memory-stats
------------- Apache processes --------------.
PID PPID Threads VMSize Private Name
---------------------------------------------.
5947 1 9 90.6 MB 0.5 MB /usr/sbin/apache2 -k start
5948 5947 1 18.9 MB 0.7 MB /usr/sbin/fcgi-pm -k start
6029 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6030 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
6031 5947 1 42.5 MB 0.3 MB /usr/sbin/apache2 -k start
6033 5947 1 42.5 MB 0.4 MB /usr/sbin/apache2 -k start
6034 5947 1 50.5 MB 0.4 MB /usr/sbin/apache2 -k start
23482 5947 1 82.6 MB 0.4 MB /usr/sbin/apache2 -k start
### Processes: 8
### Total private dirty RSS: 3.50 MB
--------- Passenger processes ---------.
PID Threads VMSize Private Name
---------------------------------------.
6026 1 10.9 MB 4.7 MB Passenger spawn server
23481 1 26.7 MB 3.0 MB Passenger FrameworkSpawner: 2.0.2
23791 1 26.8 MB 2.9 MB Passenger ApplicationSpawner: /var/www/projects/app1-foobar
23793 1 26.9 MB 17.1 MB Rails: /var/www/projects/app1-foobar
### Processes: 4
### Total private dirty RSS: 27.76 M</tt></pre>
</div></div>
<div class="paragraph"><p>The <em>Private</em> or <em>private dirty RSS</em> field shows the <strong>real</strong> memory usage of processes. Here,
we see that all the Apache worker processes only take less than 1 MB memory each.
This is a lot less than the 50 MB-ish memory usage as shown in the <em>VMSize</em> column
(which is what a lot of people think is the real memory usage, but is actually not).</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">Private dirty RSS reporting only works on Linux. Unfortunately other operating systems
don’t provide facilities for determining processes' private dirty RSS. On non-Linux systems,
the Resident Set Size is reported instead.</td>
</tr></table>
</div>
<h3 id="_inspecting_phusion_passenger_8217_s_internal_status">6.2. Inspecting Phusion Passenger’s internal status</h3><div style="clear:left"></div>
<div class="paragraph"><p>One can inspect Phusion Passenger’s internal status with the tool <tt>passenger-status</tt>.
This tool must typically be run as root. For example:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>[bash@localhost root]# passenger-status
----------- General information -----------
max = 6
count = 1
active = 0
inactive = 1
----------- Domains -----------
/var/www/projects/app1-foobar:
PID: 9617 Sessions: 0 Processed: 7 Uptime: 2m 23s</tt></pre>
</div></div>
<div class="paragraph"><p>The <em>general information</em> section shows the following information:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
max
</dt>
<dd>
<p>
The maximum number of application instances that Phusion Passenger will
spawn. This equals the value given for <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a> (Apache)
or <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a> (Nginx).
</p>
</dd>
<dt class="hdlist1">
count
</dt>
<dd>
<p>
The number of application instances that are currently alive. This value
is always less than or equal to <em>max</em>.
</p>
</dd>
<dt class="hdlist1">
active
</dt>
<dd>
<p>
The number of application instances that are currently processing
requests. This value is always less than or equal to <em>count</em>.
</p>
</dd>
<dt class="hdlist1">
inactive
</dt>
<dd>
<p>
The number of application instances that are currently <strong>not</strong> processing
requests, i.e. are idle. Idle application instances will be shutdown after a while,
as can be specified with <a href="#PassengerPoolIdleTime">PassengerPoolIdleTime (Apache)</a>/<a href="#PassengerPoolIdleTime">passenger_pool_idle_time (Nginx)</a> (unless this
value is set to 0, in which case application instances are never shut down via idle
time). The value of <em>inactive</em> equals <tt>count - active</tt>.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>The <em>domains</em> section shows, for each application directory, information about running
application instances:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
Sessions
</dt>
<dd>
<p>
Shows how many HTTP client are currently in the queue of that application
Instance, waiting to be processed.
</p>
</dd>
<dt class="hdlist1">
Processed
</dt>
<dd>
<p>
Indicates how many requests the instance has served until now. <strong>Tip:</strong> it’s
possible to limit this number with the <a href="#PassengerMaxRequests">PassengerMaxRequests</a>
configuration directive.
</p>
</dd>
<dt class="hdlist1">
Uptime
</dt>
<dd>
<p>
Shows for how long the application instance has been running.
</p>
</dd>
</dl></div>
<div class="paragraph"><p>Since Phusion Passenger uses fair load balancing by default, the number of sessions for the
application instances should be fairly close to each other. For example, this is fairly
normal:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 4268 Sessions: 0 Processed: 5 Uptime: 4m 52s
PID: 4265 Sessions: 1 Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 Processed: 7 Uptime: 3m 14s</tt></pre>
</div></div>
<div class="paragraph"><p>But if you see a "spike", i.e. an application instance has an unusually high number of
sessions compared to the others, then there might be a problem:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
PID: 17468 Sessions: 8 <-+ Processed: 2 Uptime: 4m 47s
PID: 4265 Sessions: 1 | Processed: 6 Uptime: 5m 38s
PID: 4275 Sessions: 1 | Processed: 7 Uptime: 3m 14s
|
+---- "spike"</tt></pre>
</div></div>
<div class="paragraph"><p>Possible reasons why spikes can occur:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Your application is busy processing a request that takes a very long time.
If this is the case, then you might want to turn
<a href="#PassengerUseGlobalQueue">global queuing</a> on.
</p>
</li>
<li>
<p>
Your application is frozen, i.e. has stopped responding. See
<a href="#debugging_frozen">Debugging frozen applications</a> for tips.
</p>
</li>
</ol></div>
<h3 id="debugging_frozen">6.3. Debugging frozen applications</h3><div style="clear:left"></div>
<div class="paragraph"><p>If one of your application instances is frozen (stopped responding), then you
can figure out where it is frozen by killing it with <em>SIGABRT</em>. This will cause the
application to raise an exception, with a backtrace.</p></div>
<div class="paragraph"><p>The exception (with full backtrace information) is normally logged into the Apache
error log. But if your application or if its web framework has its own exception logging
routines, then exceptions might be logged into the application’s log files instead.
This is the case with Ruby on Rails. So if you kill a Ruby on Rails application with
<em>SIGABRT</em>, please check the application’s <em>production.log</em> first (assuming that you’re
running it in a <em>production</em> environment). If you don’t see a backtrace there, check
the Apache error log.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">It is safe to kill application instances, even in live environments. Phusion Passenger
will restart killed application instances, as if nothing bad happened.</td>
</tr></table>
</div>
</div>
<h2 id="_tips">7. Tips</h2>
<div class="sectionbody">
<h3 id="user_switching">7.1. User switching (security)</h3><div style="clear:left"></div>
<div class="paragraph"><p>There is a problem that plagues most PHP web hosts, namely the fact that all PHP
applications are run in the same user context as the web server. So for
example, Joe’s PHP application will be able to read Jane’s PHP application’s
passwords. This is obviously undesirable on many servers.</p></div>
<div class="paragraph"><p>Phusion Passenger solves this problem by implementing <em>user switching</em>. A Rails
application is started as the owner of the file <em>config/environment.rb</em>,
and a Rack application is started as the owner of the file <em>config.ru</em>.
So if <em>/home/webapps/foo/config/environment.rb</em> is owned by <em>joe</em>, then Phusion
Passenger will launch the corresponding Rails application as <em>joe</em> as well.</p></div>
<div class="paragraph"><p>This behavior is the default, and you don’t need to configure anything. But
there are things that you should keep in mind:</p></div>
<div class="ulist"><ul>
<li>
<p>
The owner of <em>environment.rb</em> must have read access to the Rails application’s
folder, and read/write access to the Rails application’s <em>logs</em> folder.
Likewise, the owner of <em>config.ru</em> must have read access to the Rack application’s
folder.
</p>
</li>
<li>
<p>
This feature is only available if Apache is started by <em>root</em>. This is the
case on most Apache installations.
</p>
</li>
<li>
<p>
Under no circumstances will applications be run as <em>root</em>. If
<em>environment.rb</em>/<em>config.ru</em> is owned as root or by an unknown user, then the
Rails/Rack application will run as the user specified by
<a href="#PassengerDefaultUser">PassengerDefaultUser (Apache)</a>/<a href="#PassengerDefaultUser">passenger_default_user (Nginx)</a>.
</p>
</li>
</ul></div>
<div class="paragraph"><p>User switching can be disabled with the
<a href="#PassengerUserSwitching">PassengerUserSwitching (Apache)</a>/<a href="#PassengerUserSwitching">passenger_user_switching (Nginx)</a>
option.</p></div>
<h3 id="reducing_memory_usage">7.2. Reducing memory consumption of Ruby on Rails applications by 33%</h3><div style="clear:left"></div>
<div class="paragraph"><p>Is it possible to reduce memory consumption of your Rails applications by 33% on average,
by using <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.
Please visit the website for details.</p></div>
<div class="paragraph"><p>Note that this feature does not apply to Rack applications.</p></div>
<h3 id="capistrano">7.3. Capistrano recipe</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger can be combined with <a href="http://capify.org/">Capistrano</a>.
The following Capistrano recipe demonstrates Phusion Passenger support.
It assumes that you’re using Git as version control system.</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>set :application, "myapp"
set :domain, "example.com"
set :repository, "ssh://#{domain}/path-to-your-git-repo/#{application}.git"
set :use_sudo, false
set :deploy_to, "/path-to-your-web-app-directory/#{application}"
set :scm, "git"
role :app, domain
role :web, domain
role :db, domain, :primary => true
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end</tt></pre>
</div></div>
<h3 id="moving_phusion_passenger">7.4. Moving Phusion Passenger to a different directory</h3><div style="clear:left"></div>
<div class="paragraph"><p>It is possible to relocate the Phusion Passenger files to a different directory. It
involves two steps:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Moving the directory.
</p>
</li>
<li>
<p>
Updating the “PassengerRoot” configuration option in Apache.
</p>
</li>
</ol></div>
<div class="paragraph"><p>For example, if Phusion Passenger is located in <em>/opt/passenger/</em>, and you’d like to
move it to <em>/usr/local/passenger/</em>, then do this:</p></div>
<div class="olist arabic"><ol class="arabic">
<li>
<p>
Run the following command:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>mv /opt/passenger /usr/local/passenger</tt></pre>
</div></div>
</li>
<li>
<p>
Edit your Apache configuration file, and set:
</p>
<div class="listingblock">
<div class="content">
<pre><tt>PassengerRoot /usr/local/passenger</tt></pre>
</div></div>
</li>
</ol></div>
<h3 id="_installing_multiple_ruby_on_rails_versions">7.5. Installing multiple Ruby on Rails versions</h3><div style="clear:left"></div>
<div class="paragraph"><p>Each Ruby on Rails applications that are going to be deployed may require a
specific Ruby on Rails version. You can install a specific version with
this command:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>gem install rails -v X.X.X</tt></pre>
</div></div>
<div class="paragraph"><p>where <em>X.X.X</em> is the version number of Ruby on Rails.</p></div>
<div class="paragraph"><p>All of these versions will exist in parallel, and will not conflict with each
other. Phusion Passenger will automatically make use of the correct version.</p></div>
<h3 id="_making_the_application_restart_after_each_request">7.6. Making the application restart after each request</h3><div style="clear:left"></div>
<div class="paragraph"><p>In some situations it might be desirable to restart the web application after
each request, for example when developing a non-Rails application that doesn’t
support code reloading, or when developing a web framework.</p></div>
<div class="paragraph"><p>To achieve this, simply create the file <em>tmp/always_restart.txt</em> in your
application’s root folder. Unlike <em>restart.txt</em>, Phusion Passenger does not
check for this file’s timestamp: Phusion Passenger will always restart the
application, as long as <em>always_restart.txt</em> exists.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">If you’re just developing a Rails application then you probably don’t need
this feature. If you set <em>RailsEnv development</em> in your Apache configuration,
then Rails will automatically reload your application code after each request.
<em>always_restart.txt</em> is only useful if you’re working on Ruby on Rails itself,
or when you’re not developing a Rails application and your web framework
does not support code reloading.</td>
</tr></table>
</div>
<h3 id="sub_uri_deployment_uri_fix">7.7. How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</h3><div style="clear:left"></div>
<div class="paragraph"><p>Some people experience broken images and other broken static assets when they
deploy their application to a sub-URI (i.e. <em>http://mysite.com/railsapp/</em>).
The reason for this usually is that you used a
static URI for your image in the views. This means your <em>img</em> source probably refers
to something like <em>/images/foo.jpg</em>. The leading slash means that it’s an absolute URI:
you’re telling the browser to always load <em>http://mysite.com/images/foo.jpg</em> no
matter what. The problem is that the image is actually at
<em>http://mysite.com/railsapp/images/foo.jpg</em>. There are two ways to fix this.</p></div>
<div class="paragraph"><p>The first way (not recommended) is to change your view templates to refer to
<em>images/foo.jpg</em>. This is a relative URI: note the lack of a leading slash). What
this does is making the path relative to the current URI. The problem is that if you
use restful URIs, then your images will probably break again when you add a level to
the URI.
For example, when you’re at <em>http://mysite.com/railsapp</em> the browser will look for
<em>http://mysite.com/railsapp/images/foo.jpg</em>. But when you’re at
<em>http://mysite.com/railsapp/controller</em>. the browser will look for
<em>http://mysite.com/railsapp/controller/images/foo.jpg</em>.
So relative URIs usually don’t work well with layout templates.</p></div>
<div class="paragraph"><p>The second and highly recommended way is to always use Rails helper methods to
output tags for static assets. These helper methods automatically take care
of prepending the base URI that you’ve deployed the application to. For images
there is <tt>image_tag</tt>, for JavaScript there is <tt>javascript_include_tag</tt> and for
CSS there is <tt>stylesheet_link_tag</tt>. In the above example you would simply remove
the <em><img></em> HTML tag and replace it with inline Ruby like this:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt><%= image_tag("foo.jpg") %></tt></pre>
</div></div>
<div class="paragraph"><p>This will generate the proper image tag to <tt>$RAILS_ROOT/public/images/foo.jpg</tt>
so that your images will always work no matter what sub-URI you’ve deployed to.</p></div>
<div class="paragraph"><p>These helper methods are more valuable than you may think. For example they also
append a timestamp to the URI to better facilitate HTTP caching. For more information,
please refer to
<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">the Rails API docs</a>.</p></div>
</div>
<h2 id="_appendix_a_about_this_document">8. Appendix A: About this document</h2>
<div class="sectionbody">
<div class="paragraph"><p>The text of this document is licensed under the
<a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
Attribution-Share Alike 3.0 Unported License</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://creativecommons.org/licenses/by-sa/3.0/">
<img src="images/by_sa.png" alt="images/by_sa.png" />
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is brought to you by <a href="http://www.phusion.nl/">Phusion</a>.</p></div>
<div class="paragraph"><p><span class="image">
<a class="image" href="http://www.phusion.nl/">
<img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
</a>
</span></p></div>
<div class="paragraph"><p>Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.</p></div>
</div>
<h2 id="_appendix_b_terminology">9. Appendix B: Terminology</h2>
<div class="sectionbody">
<h3 id="application_root">9.1. Application root</h3><div style="clear:left"></div>
<div class="paragraph"><p>The root directory of an application that’s served by Phusion Passenger.</p></div>
<div class="paragraph"><p>In case of Ruby on Rails applications, this is the directory that contains
<em>Rakefile</em>, <em>app/</em>, <em>config/</em>, <em>public/</em>, etc. In other words, the directory
pointed to by <tt>RAILS_ROOT</tt>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/foo/ <------ This is the Rails application's application root!
|
+- app/
| |
| +- controllers/
| |
| +- models/
| |
| +- views/
|
+- config/
| |
| +- environment.rb
| |
| +- ...
|
+- public/
| |
| +- ...
|
+- ...</tt></pre>
</div></div>
<div class="paragraph"><p>In case of Rack applications, this is the directory that contains <em>config.ru</em>.
For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/bar/ <----- This is the Rack application's application root!
|
+- public/
| |
| +- ...
|
+- config.ru
|
+- ...</tt></pre>
</div></div>
<div class="paragraph"><p>In case of Python (WSGI) applications, this is the directory that contains
<em>passenger_wsgi.py</em>. For example, take the following directory structure:</p></div>
<div class="listingblock">
<div class="content">
<pre><tt>/apps/baz/ <----- This is the WSGI application's application root!
|
+- public/
| |
| +- ...
|
+- passenger_wsgi.py
|
+- ...</tt></pre>
</div></div>
</div>
<h2 id="spawning_methods_explained">10. Appendix C: Spawning methods explained</h2>
<div class="sectionbody">
<div class="paragraph"><p>At its core, Phusion Passenger is an HTTP proxy and process manager. It spawns
Ruby on Rails/Rack/WSGI worker processes (which may also be referred to as
<em>backend processes</em>), and forwards incoming HTTP request to one of the worker
processes.</p></div>
<div class="paragraph"><p>While this may sound simple, there’s not just one way to spawn worker processes.
Let’s go over the different spawning methods. For simplicity’s sake, let’s
assume that we’re only talking about Ruby on Rails applications.</p></div>
<h3 id="_the_most_straightforward_and_traditional_way_conservative_spawning">10.1. The most straightforward and traditional way: conservative spawning</h3><div style="clear:left"></div>
<div class="paragraph"><p>Phusion Passenger could create a new Ruby process, which will then load the
Rails application along with the entire Rails framework. This process will then
enter an request handling main loop.</p></div>
<div class="paragraph"><p>This is the most straightforward way to spawn worker processes. If you’re
familiar with the Mongrel application server, then this approach is exactly
what mongrel_cluster performs: it creates N worker processes, each which loads
a full copy of the Rails application and the Rails framework in memory. The Thin
application server employs pretty much the same approach.</p></div>
<div class="paragraph"><p>Note that Phusion Passenger’s version of conservative spawning differs slightly
from mongrel_cluster. Mongrel_cluster creates entirely new Ruby processes. In
programmers jargon, mongrel_cluster creates new Ruby processes by forking the
current process and exec()-ing a new Ruby interpreter. Phusion Passenger on the
other hand creates processes that reuse the already loaded Ruby interpreter. In
programmers jargon, Phusion Passenger calls fork(), but not exec().</p></div>
<h3 id="_the_smart_spawning_method">10.2. The smart spawning method</h3><div style="clear:left"></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
<td class="content">Smart spawning is only available for Ruby on Rails applications, not for
Rack applications or WSGI applications.</td>
</tr></table>
</div>
<div class="paragraph"><p>While conservative spawning works well, it’s not as efficient as it could be
because each worker process has its own private copy of the Rails application
as well as the Rails framework. This wastes memory as well as startup time.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/conservative_spawning.png" alt="Worker processes and conservative spawning" />
</span><br />
<em>Figure: Worker processes and conservative spawning. Each worker process has its
own private copy of the application code and Rails framework code.</em></p></div>
<div class="paragraph"><p>It is possible to make the different worker processes share the memory occupied
by application and Rails framework code, by utilizing so-called
copy-on-write semantics of the virtual memory system on modern operating
systems. As a side effect, the startup time is also reduced. This is technique
is exploited by Phusion Passenger’s <em>smart</em> and <em>smart-lv2</em> spawn methods.</p></div>
<h4 id="_how_it_works">10.2.1. How it works</h4>
<div class="paragraph"><p>When the <em>smart-lv2</em> spawn method is being used, Phusion Passenger will first
create a so-called <em>ApplicationSpawner server</em> process. This process loads the
entire Rails application along with the Rails framework, by loading
<em>environment.rb</em>. Then, whenever Phusion Passenger needs a new worker process,
it will instruct the ApplicationSpawner server to do so. The ApplicationSpawner
server will create a worker new process
that reuses the already loaded Rails application/framework. Creating a worker
process through an already running ApplicationSpawner server is very fast, about
10 times faster than loading the Rails application/framework from scratch. If
the Ruby interpreter is copy-on-write friendly (that is, if you’re running
<a href="#reducing_memory_usage">Ruby Enterprise Edition</a>) then all created worker
processes will share as much common
memory as possible. That is, they will all share the same application and Rails
framework code.</p></div>
<div class="paragraph"><p><span class="image">
<img src="images/smart-lv2.png" alt="images/smart-lv2.png" />
</span><br />
<em>Figure: Worker processes and the smart-lv2 spawn method. All worker processes,
as well as the ApplicationSpawner, share the same application code and Rails
framework code.</em></p></div>
<div class="paragraph"><p>The <em>smart</em> spawn method goes even further, by caching the Rails framework in
another process called the <em>FrameworkSpawner server</em>. This process only loads
the Rails framework, not the application. When a FrameworkSpawner server is
instructed to create a new worker process, it will create a new
ApplicationSpawner to which the instruction will be delegated. All those
ApplicationSpawner servers, as well as all worker processes created by those
ApplicationSpawner servers, will share the same Rails framework code.</p></div>
<div class="paragraph"><p>The <em>smart-lv2</em> method allows different worker processes that belong to the same
application to share memory. The <em>smart</em> method allows different worker
processes - that happen to use the same Rails version - to share memory, even if
they don’t belong to the same application.</p></div>
<div class="paragraph"><p>Notes:</p></div>
<div class="ulist"><ul>
<li>
<p>
Vendored Rails frameworks cannot be shared by different applications, even if
both vendored Rails frameworks are the same version. So for efficiency reasons
we don’t recommend vendoring Rails.
</p>
</li>
<li>
<p>
ApplicationSpawner and FrameworkSpawner servers have an idle timeout just
like worker processes. If an ApplicationSpawner/FrameworkSpawner server hasn’t
been instructed to do anything for a while, it will be shutdown in order to
conserve memory. This idle timeout is configurable.
</p>
</li>
</ul></div>
<h4 id="_summary_of_benefits">10.2.2. Summary of benefits</h4>
<div class="paragraph"><p>Suppose that Phusion Passenger needs a new worker process for an application
that uses Rails 2.2.1.</p></div>
<div class="ulist"><ul>
<li>
<p>
If the <em>smart-lv2</em> spawning method is used, and an ApplicationSpawner server
for this application is already running, then worker process creation time is
about 10 times faster than conservative spawning. This worker process will also
share application and Rails framework code memory with the ApplicationSpawner
server and the worker processes that had been spawned by this ApplicationSpawner
server.
</p>
</li>
<li>
<p>
If the <em>smart</em> spawning method is used, and a FrameworkSpawner server for
Rails 2.2.1 is already running, but no ApplicationSpawner server for this
application is running, then worker process creation time is about 2 times
faster than conservative spawning. If there is an ApplicationSpawner server
for this application running, then worker process creation time is about 10
times faster. This worker process will also share application and Rails
framework code memory with the ApplicationSpawner and FrameworkSpawner
servers.
</p>
</li>
</ul></div>
<div class="paragraph"><p>You could compare ApplicationSpawner and FrameworkSpawner servers with stem
cells, that have the ability to quickly change into more specific cells (worker
process).</p></div>
<div class="paragraph"><p>In practice, the smart spawning methods could mean a memory saving of about 33%,
assuming that your Ruby interpreter is <a href="#reducing_memory_usage">copy-on-write friendly</a>.</p></div>
<div class="paragraph"><p>Of course, smart spawning is not without gotchas. But if you understand the
gotchas you can easily reap the benefits of smart spawning.</p></div>
<h3 id="_smart_spawning_gotcha_1_unintential_file_descriptor_sharing">10.3. Smart spawning gotcha #1: unintential file descriptor sharing</h3><div style="clear:left"></div>
<div class="paragraph"><p>Because worker processes are created by forking from an ApplicationSpawner
server, it will share all file descriptors that are opened by the
ApplicationSpawner server. (This is part of the semantics of the Unix
<em>fork()</em> system call. You might want to Google it if you’re not familiar with
it.) A file descriptor is a handle which can be an opened file, an opened socket
connection, a pipe, etc. If different worker processes write to such a file
descriptor at the same time, then their write calls will be interleaved, which
may potentially cause problems.</p></div>
<div class="paragraph"><p>The problem commonly involves socket connections that are unintentially being
shared. You can fix it by closing and reestablishing the connection when Phusion
Passenger is creating a new worker process. Phusion Passenger provides the API
call <tt>PhusionPassenger.on_event(:starting_worker_process)</tt> to do so. So you
could insert the following code in your <em>environment.rb</em>:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to reestablish socket connections here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>Note that Phusion Passenger automatically reestablishes the connection to the
database upon creating a new worker process, which is why you normally do not
encounter any database issues when using smart spawning mode.</p></div>
<h4 id="_example_1_memcached_connection_sharing_harmful">10.3.1. Example 1: Memcached connection sharing (harmful)</h4>
<div class="paragraph"><p>Suppose we have a Rails application that connects to a Memcached server in
<em>environment.rb</em>. This causes the ApplicationSpawner to have a socket connection
(file descriptor) to the Memcached server, as shown in the following figure:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |-----------[Memcached server]
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Phusion Passenger then proceeds with creating a new Rails worker process, which
is to process incoming HTTP requests. The result will look like this:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Since a <em>fork()</em> makes a (virtual) complete copy of a process, all its file
descriptors will be copied as well. What we see here is that ApplicationSpawner
and Worker process 1 both share the same connection to Memcached.</p></div>
<div class="paragraph"><p>Now supposed that your site gets Slashdotted and Phusion Passenger needs to
spawn another worker process. It does so by forking ApplicationSpawner. The
result is now as follows:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ |
|
+--------------------+ |
| Worker process 1 |-----/|
+--------------------+ |
|
+--------------------+ |
| Worker process 2 |-----/
+--------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>As you can see, Worker process 1 and Worker process 2 have the same Memcache
connection.</p></div>
<div class="paragraph"><p>Suppose that users Joe and Jane visit your website at the same time. Joe’s
request is handled by Worker process 1, and Jane’s request is handled by Worker
process 2. Both worker processes want to fetch something from Memcached. Suppose
that in order to do that, both handlers need to send a "FETCH" command to Memcached.</p></div>
<div class="paragraph"><p>But suppose that, after worker process 1 having only sent "FE", a context switch
occurs, and worker process 2 starts sending a "FETCH" command to Memcached as
well. If worker process 2 succeeds in sending only one bye, <em>F</em>, then Memcached
will receive a command which begins with "FEF", a command that it does not
recognize. In other words: the data from both handlers get interleaved. And thus
Memcached is forced to handle this as an error.</p></div>
<div class="paragraph"><p>This problem can be solved by reestablishing the connection to Memcached after forking:</p></div>
<div class="literalblock">
<div class="content">
<pre><tt>+--------------------+
| ApplicationSpawner |------+----[Memcached server]
+--------------------+ | |
| |
+--------------------+ | |
| Worker process 1 |-----/| |
+--------------------+ | | <--- created this
X | new
| connection
X <-- closed this |
+--------------------+ | old |
| Worker process 2 |-----/ connection |
+--------------------+ |
| |
+-------------------------------------+</tt></pre>
</div></div>
<div class="paragraph"><p>Worker process 2 now has its own, separate communication channel with Memcached.
The code in <em>environment.rb</em> looks like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
reestablish_connection_to_memcached
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<h4 id="_example_2_log_file_sharing_not_harmful">10.3.2. Example 2: Log file sharing (not harmful)</h4>
<div class="paragraph"><p>There are also cases in which unintential file descriptor sharing is not harmful.
One such case is log file file descriptor sharing. Even if two processes write
to the log file at the same time, the worst thing that can happen is that the
data in the log file is interleaved.</p></div>
<div class="paragraph"><p>To guarantee that the data written to the log file is never interleaved, you
must synchronize write access via an inter-process synchronization mechanism,
such as file locks. Reopening the log file, like you would have done in the
Memcached example, doesn’t help.</p></div>
<h3 id="_smart_spawning_gotcha_2_the_need_to_revive_threads">10.4. Smart spawning gotcha #2: the need to revive threads</h3><div style="clear:left"></div>
<div class="paragraph"><p>Another part of the <em>fork()</em> system call’s semantics is the fact that threads
disappear after a fork call. So if you’ve created any threads in environment.rb,
then those threads will no longer be running in newly created worker process.
You need to revive them when a new worker process is created. Use the
<tt>:starting_worker_process</tt> event that Phusion Passenger provides, like this:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.11.1
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
<span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
<span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
<span style="color: #990000">...</span> code to revive threads here <span style="color: #990000">...</span>
<span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
<span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<h3 id="_smart_spawning_gotcha_3_code_load_order">10.5. Smart spawning gotcha #3: code load order</h3><div style="clear:left"></div>
<div class="paragraph"><p>This gotcha is only applicable to the <em>smart</em> spawn method, not the <em>smart-lv2</em>
spawn method.</p></div>
<div class="paragraph"><p>If your application expects the Rails framework to be not loaded during the
beginning of <em>environment.rb</em>, then it can cause problems when an
ApplicationSpawner is created from a FrameworkSpawner, which already has the
Rails framework loaded. The most common case is when applications try to patch
Rails by dropping a modified file that has the same name as Rails’s own file,
in a path that comes earlier in the Ruby search path.</p></div>
<div class="paragraph"><p>For example, suppose that we have an application which has a patched version
of <em>active_record/base.rb</em> located in <em>RAILS_ROOT/lib/patches</em>, and
<em>RAILS_ROOT/lib/patches</em> comes first in the Ruby load path. When conservative
spawning is used, the patched version of <em>base.rb</em> is properly loaded. When
<em>smart</em> (not <em>smart-lv2</em>) spawning is used, the original <em>base.rb</em> is used
because it was already loaded, so a subsequent <tt>require "active_record/base"</tt>
has no effect.</p></div>
</div>
</div>
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
Last updated 2010-03-05 10:35:16 CEST
</div>
</div>
</body>
</html>
|