乘客使用nginx指定选项来构建
Phusion Passenger提供了一个能够构建带有nginx的passenger-install-nginx-module,但是自动构建的nginx可能没有集成所需的模块。
(例如,可能没有HTTP/2(ALPN)支持等)
乘客安装Nginx模块时,即使在这种情况下也可以轻松处理。
在中国合格的大学生源于良好的前提条件。
我正在以以下条件进行确认。
-
- Phusion PassengerをGemインストール済
- passenger 5.2.2
准备nginx的源代码。
获取并解压所需版本的nginx源代码。
- https://nginx.org/en/download.html
# cd /usr/local/src
# curl -L -O https://nginx.org/download/nginx-1.12.2.tar.gz
# tar xofz nginx-1.12.2.tar.gz
准备其他模块的源代码。
如果在后续的配置过程中需要指定某些内容,也可以在这里准备好。例如,为了支持ALPN,需要使用OpenSSL的版本1.0.2或更高,因此需要获取和解压源代码。
- https://www.openssl.org/source/
# cd /usr/local/src
# curl -L -O https://www.openssl.org/source/openssl-1.1.0h.tar.gz
# tar xofz openssl-1.1.0h.tar.gz
执行passenger-install-nginx-module
如果你不想参与对话类型活动,可以选择其他选项。
转向第二条路
执行 passenger-install-nginx-module 命令,并按照正常步骤进行,直到出现“是否自动下载并安装 Nginx?”的提示为止。
# passenger-install-nginx-module
只需要一个选项
Automatically download and install Nginx?
Nginx doesn't support loadable modules such as some other web servers do,
so in order to install Nginx with Passenger support, it must be recompiled.
Do you want this installer to download, compile and install Nginx for you?
1. Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.12.2 with Passenger
support, but with no other additional third party modules, will be
installed for you to a directory of your choice.
2. No: I want to customize my Nginx installation. (for advanced users)
Choose this if you want to compile Nginx with more third party modules
besides Passenger, or if you need to pass additional options to Nginx's
'configure' script. This installer will 1) ask you for the location of
the Nginx source code, 2) run the 'configure' script according to your
instructions, and 3) run 'make install'.
Whichever you choose, if you already have an existing Nginx configuration file,
then it will be preserved.
Enter your choice (1 or 2) or press Ctrl-C to abort:
在这里输入数字2然后继续。
Enter your choice (1 or 2) or press Ctrl-C to abort: 2
指定源代码
然后,您会被问到nginx源代码的位置在哪里。
Where is your Nginx source code located?
Please specify the directory:
请输入您之前设置好的地点并前进。
Please specify the directory: /usr/local/src/nginx-1.12.2
指定安装目录
接下来,会问你nginx的安装目录。
Where do you want to install Nginx to?
Please specify a prefix directory [/opt/nginx]:
如果你没有问题的话,就直接按Enter键,在/opt/nginx上进行操作。如果需要的话,就输入位置并继续。
添加配置选项
然后,我们会询问你想在配置时添加的选项,正如你所期待的。
Extra Nginx configure options
If you want to pass extra arguments to the Nginx 'configure' script, then
please specify them. If not, then specify nothing and press Enter.
If you specify nothing then the 'configure' script will be run as follows:
sh ./configure --prefix='/opt/nginx' --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-cc-opt=-Wno-error --with-ld-opt='' --add-module='/path/to/passenger-5.2.2/src/nginx_module'
Extra arguments to pass to configure script:
在这里可以根据喜好选择选项。
这次为了支持HTTP/2(ALPN),我们使用了–with-openssl=来指定了OpenSSL的源代码。
Extra arguments to pass to configure script: --with-openssl='/usr/local/src/openssl-1.1.0h'
当点击“进入”后,会显示包括您输入的选项在内的确认信息。
Confirm configure flags
The Nginx configure script will be run as follows:
sh ./configure --prefix='/opt/nginx' --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-cc-opt=-Wno-error --with-ld-opt='' --add-module='/path/to/passenger/src/nginx_module' --with-openssl='/usr/local/src/openssl-1.1.0h'
Is this what you want? (yes/no) [default=yes]:
如果在这里输入 “no”,您将返回到 “Extra Nginx configure options”,可以重新进行设置。
如果没有问题,您可以选择 “yes” 或直接按下 “Enter” 继续。
建筑
后面等待建设完成并显示以下信息。
Nginx with Passenger support was successfully installed.
The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.
This installer has already modified the configuration file for you! The
following configuration snippet was inserted:
http {
...
passenger_root /path/to/passenger;
passenger_ruby /path/to/ruby;
...
}
After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.
Press ENTER to continue.
输入Enter即完成。
Deploying a web application
To learn how to deploy a web app on Passenger, please follow the deployment
guide:
https://www.phusionpassenger.com/library/deploy/nginx/deploy/
Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com
Passenger® is a registered trademark of Phusion Holding B.V.
确认
我会确认是否已经按预期构建了nginx。我将运行安装目录下的sbin/nginx -V来执行此操作。
# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.1.0h 27 Mar 2018
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-cc-opt=-Wno-error --with-ld-opt= --add-module=/path/to/passenger/src/nginx_module --with-openssl=/usr/local/src/openssl-1.1.0h
在这个例子中,我们可以确认使用的 OpenSSL 版本是指定的源代码版本,并且还包含了在 configure 参数中指定的选项。
辛苦了。
非对话式建筑
可以通过在 passenger-install-nginx-module 命令后传递参数来实现非交互式的方式进行上述的构建工作。
# passenger-install-nginx-module --help
Usage: passenger-install-nginx-module [options]
Options:
--auto Automatically confirm 'Press ENTER to
continue' prompts.
--prefix=DIR Use the given Nginx install prefix instead
of asking for it interactively.
--auto-download Download and install Nginx automatically,
instead of asking interactively whether to
download+install or to use an existing
Nginx source directory.
--nginx-source-dir=DIR Compile and install Nginx using the given
Nginx source directory, instead of
interactively asking to download+install
or to use an existing Nginx source
directory. Conflicts with --auto-download.
--extra-configure-flags=STRING
Pass these extra flags to Nginx's
'configure' script, instead of asking for
it interactively. Specify 'none' if you
do not want to pass additional flags but do
not want this installer to ask
interactively either.
--languages NAMES Comma-separated list of interested
languages (e.g.
'ruby,python,nodejs,meteor')
--force-colors Display colors even if stdout is not a TTY
如果按照本篇文章的例子进行设定,将会得到与对话式相似的结果。
passenger-install-nginx-module --auto --prefix=/opt/nginx --nginx-source-dir='/usr/local/src/nginx-1.12.2' --extra-configure-flags="--with-openssl='/usr/local/src/openssl-1.1.0h'"