NGINX Unit の概要からインストール

2017年9月6日に発表された NGINX Unitの概要からインストールの手順までをマニュアルの参考訳とともにお伝えします。
 

NGINX Unitは、複数の言語でアプリケーションを実行できるように設計された動的Webアプリケーションサーバです。

NGINX Unitは軽量、多言語、そしてAPIを介して動的に設定されます。 サーバーの設計により、エンジニアリングまたはオペレーションによって必要に応じて特定のアプリケーションパラメータを再構成することができます。

NGINXユニットは現在、ベータ版として利用可能です。 したがって、テスト環境での使用を目的にしており、本番環境での使用はお勧めしません。

NGINX Unit の主な機能

  • RESTful JSON APIを使用した完全動的再構成
  • 複数のアプリケーション言語とバージョンを同時に実行
  • 動的アプリケーションプロセス管理(近日公開予定)
  • TLSサポート(近日公開予定)
  • TCP、HTTP、HTTPS、HTTP/2 ルーティングとプロキシ(近日公開予定)

サポートされているアプリケーション言語

  • Python
  • PHP
  • Go
  • JavaScript / Node.js(近日公開予定)
  • Java(近日公開予定)
  • Ruby(近日公開予定)
 
NGINX Unitのドキュメント原文はこちらを参照ください。
 

NGINX Unit インストール

System Requirements

NGINXユニットは、以下のシステムでコンパイルされ実行されます。
 
  • Linux 2.6 or later
  • FreeBSD 9 or later
  • MacOS X
  • Solaris 11
  • Architectures:
  • i386
  • amd64
  • powerpc
  • arm
 
NGINXユニットで動作するアプリケーションの場合は、それぞれのプログラミング言語が必要です。
 
  • Python 2.6, 2.7, 3
  • PHP 5, 7
  • Go 1.6 or later

同じシステムに複数のバージョンの同じ言語をインストールすることができます。

プリコンパイル済みパッケージ

Unitのプリコンパイルされたバイナリは、CentOS 7.0およびUbuntu 16.04 LTSで使用できます。

CentOSパッケージ

  1. /etc/yum.repos.d/unit.repoファイルを次のように作成します内容:
    [unit]
    name=unit repo
    baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
    gpgcheck=0
    enabled=1
  2. ユニットパッケージをダウンロードする:
    # yum Install unit
 
[参考] 実際にAWS環境のCentOSにてインストールした場合は以下のように実行されます。
Loaded plugins: fastestmirror
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
unit | 2.9 kB 00:00
updates | 3.4 kB 00:00
(1/5): base/7/x86_64/group_gz | 156 kB 00:00
(2/5): extras/7/x86_64/primary_db | 101 kB 00:00
(3/5): base/7/x86_64/primary_db | 5.7 MB 00:00
(4/5): updates/7/x86_64/primary_db | 2.8 MB 00:01
(5/5): unit/x86_64/primary_db | 84 kB 00:01
Determining fastest mirrors
* base: www.ftp.ne.jp
* extras: www.ftp.ne.jp
* updates: www.ftp.ne.jp
Resolving Dependencies
–> Running transaction check
—> Package unit.x86_64 0:0.1-1.el7.ngx will be installed
–> Processing Dependency: libphp5-5.4.so()(64bit) for package: unit-0.1-1.el7.ngx.x86_64
–> Running transaction check
—> Package php-embedded.x86_64 0:5.4.16-42.el7 will be installed
–> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-embedded-5.4.16-42.el7.x86_64
–> Running transaction check
—> Package php-common.x86_64 0:5.4.16-42.el7 will be installed
–> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-42.el7.x86_64
–> Running transaction check
—> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
–> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
unit x86_64 0.1-1.el7.ngx unit 146 k
Installing for dependencies:
libzip x86_64 0.10.1-8.el7 base 48 k
php-common x86_64 5.4.16-42.el7 base 564 k
php-embedded x86_64 5.4.16-42.el7 base 1.3 M
Transaction Summary
================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 2.1 M
Installed size: 8.7 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/libzip-0.10.1-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for libzip-0.10.1-8.el7.x86_64.rpm is not installed
(1/4): libzip-0.10.1-8.el7.x86_64.rpm | 48 kB 00:00
(2/4): php-common-5.4.16-42.el7.x86_64.rpm | 564 kB 00:00
(3/4): php-embedded-5.4.16-42.el7.x86_64.rpm | 1.3 MB 00:00
(4/4): unit-0.1-1.el7.ngx.x86_64.rpm | 146 kB 00:00
——————————————————————————–
Total 2.0 MB/s | 2.1 MB 00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : “CentOS-7 Key (CentOS 7 Official Signing Key) “
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-3.1611.el7.centos.x86_64 (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libzip-0.10.1-8.el7.x86_64 1/4
Installing : php-common-5.4.16-42.el7.x86_64 2/4
Installing : php-embedded-5.4.16-42.el7.x86_64 3/4
Installing : unit-0.1-1.el7.ngx.x86_64 4/4
———————————————————————-
Thank you for installing NGINX Unit!
You may want to load demo configuration and check a couple of apps:
# service unitd start
# service unitd restoreconfig /usr/share/doc/unit/examples/example.config
# curl http://localhost:8300/
# curl http://localhost:8400/
Online documentation is available at http://unit.nginx.org/
———————————————————————-
Verifying : php-embedded-5.4.16-42.el7.x86_64 1/4
Verifying : libzip-0.10.1-8.el7.x86_64 2/4
Verifying : php-common-5.4.16-42.el7.x86_64 3/4
Verifying : unit-0.1-1.el7.ngx.x86_64 4/4
Installed:
unit.x86_64 0:0.1-1.el7.ngx
Dependency Installed:
libzip.x86_64 0:0.10.1-8.el7         php-common.x86_64 0:5.4.16-42.el7
php-embedded.x86_64 0:5.4.16-42.el7
Complete!
 

同時に libzip、php-common、php-embedded の3パッケージがインストールされました。

unitのデモコンフィグレーションがインストールの最後のメッセージでも出力されているので試しに実行してみましょう。

# service unitd start
Redirecting to /bin/systemctl start unitd.service

 

# service unitd restoreconfig /usr/share/doc/unit/examples/example.config
Restoring configuration from /usr/share/doc/unit/examples/example.config…
{
“success”: “Reconfiguration done.”
}
参考:example.configの内容は以下の通り
# cat /usr/share/doc/unit/examples/example.config
{
“applications”: {
“example_php”: {
“type”: “php”,
“user”: “nobody”,
“workers”: 2,
“root”: “/usr/share/doc/unit/examples/php-app”,
“index”: “index.php”
},
“example_python”: {
“type”: “python”,
“user”: “nobody”,
“workers”: 2,
“path”: “/usr/share/doc/unit/examples/python-app”,
“module”: “wsgi”
},
“example_go”: {
“type”: “go”,
“user”: “nobody”,
“executable”: “/tmp/go-app”
}
},
“listeners”: {
“*:8300”: {
“application”: “example_php”
},
“*:8400”: {
“application”: “example_python”
},
“*:8500”: {
“application”: “example_go”
}
}
}

 

# curl http://localhost:8300/

PHP Logo

PHP Version 5.4.16

SystemLinux ip-172-31-5-112 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017 x86_64
Build DateNov 6 2016 00:31:38
Server APIunit
Virtual Directory Supportdisabled
Configuration File (php.ini) Path/etc
Loaded Configuration File/etc/php.ini
Scan this dir for additional .ini files/etc/php.d
Additional .ini files parsed/etc/php.d/curl.ini, /etc/php.d/fileinfo.ini, /etc/php.d/json.ini, /etc/php.d/phar.ini, /etc/php.d/zip.ini
PHP API20100412
PHP Extension20100525
Zend Extension220100525
Zend Extension BuildAPI220100525,NTS
PHP Extension BuildAPI20100525,NTS
Debug Buildno
Thread Safetydisabled
Zend Signal Handlingdisabled
Zend Memory Managerenabled
Zend Multibyte Supportdisabled
IPv6 Supportenabled
DTrace Supportdisabled
Registered PHP Streamshttps, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transportstcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filterszlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk
Zend logo This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

PHP Credits


Configuration

bz2

BZip2 SupportEnabled
Stream Wrapper supportcompress.bzip2://
Stream Filter supportbzip2.decompress, bzip2.compress
BZip2 Version1.0.6, 6-Sept-2010

calendar

Calendar supportenabled

Core

PHP Version5.4.16
DirectiveLocal ValueMaster Value
allow_url_fopenOnOn
allow_url_includeOffOff
always_populate_raw_post_dataOffOff
arg_separator.input&&
arg_separator.output&&
asp_tagsOffOff
auto_append_fileno valueno value
auto_globals_jitOnOn
auto_prepend_fileno valueno value
browscapno valueno value
default_charsetno valueno value
default_mimetypetext/htmltext/html
disable_classesno valueno value
disable_functionsno valueno value
display_errorsOffOff
display_startup_errorsOffOff
doc_rootno valueno value
docref_extno valueno value
docref_rootno valueno value
enable_dlOffOff
enable_post_data_readingOnOn
error_append_stringno valueno value
error_logno valueno value
error_prepend_stringno valueno value
error_reporting2252722527
exit_on_timeoutOffOff
expose_phpOnOn
extension_dir/usr/lib64/php/modules/usr/lib64/php/modules
file_uploadsOnOn
highlight.comment#FF8000#FF8000
highlight.default#0000BB#0000BB
highlight.html#000000#000000
highlight.keyword#007700#007700
highlight.string#DD0000#DD0000
html_errorsOnOn
ignore_repeated_errorsOffOff
ignore_repeated_sourceOffOff
ignore_user_abortOffOff
implicit_flushOffOff
include_path.:/usr/share/pear:/usr/share/php.:/usr/share/pear:/usr/share/php
log_errorsOnOn
log_errors_max_len10241024
mail.add_x_headerOnOn
mail.force_extra_parametersno valueno value
mail.logno valueno value
max_execution_time3030
max_file_uploads2020
max_input_nesting_level6464
max_input_time6060
max_input_vars10001000
memory_limit128M128M
open_basedirno valueno value
output_buffering40964096
output_handlerno valueno value
post_max_size8M8M
precision1414
realpath_cache_size16K16K
realpath_cache_ttl120120
register_argc_argvOffOff
report_memleaksOnOn
report_zend_debugOnOn
request_orderGPGP
sendmail_fromno valueno value
sendmail_path/usr/sbin/sendmail -t -i/usr/sbin/sendmail -t -i
serialize_precision1717
short_open_tagOffOff
SMTPlocalhostlocalhost
smtp_port2525
sql.safe_modeOffOff
track_errorsOffOff
unserialize_callback_funcno valueno value
upload_max_filesize2M2M
upload_tmp_dirno valueno value
user_dirno valueno value
user_ini.cache_ttl300300
user_ini.filename.user.ini.user.ini
variables_orderGPCSGPCS
xmlrpc_error_number00
xmlrpc_errorsOffOff
zend.detect_unicodeOnOn
zend.enable_gcOnOn
zend.multibyteOffOff
zend.script_encodingno valueno value

ctype

ctype functionsenabled

curl

cURL supportenabled
cURL Information7.29.0
Age3
Features
AsynchDNSYes
DebugNo
GSS-NegotiateYes
IDNYes
IPv6Yes
LargefileYes
NTLMYes
SPNEGONo
SSLYes
SSPINo
krb4No
libzYes
CharConvNo
Protocolsdict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Hostx86_64-redhat-linux-gnu
SSL VersionNSS/3.21 Basic ECC
ZLib Version1.2.7
libSSH Versionlibssh2/1.4.3

date

date/time supportenabled
“Olson” Timezone Database Version0.system
Timezone Databaseinternal
Default timezoneUTC
DirectiveLocal ValueMaster Value
date.default_latitude31.766731.7667
date.default_longitude35.233335.2333
date.sunrise_zenith90.58333390.583333
date.sunset_zenith90.58333390.583333
date.timezoneno valueno value

ereg

Regex LibraryBundled library enabled

exif

EXIF Supportenabled
EXIF Version1.4 $Id$
Supported EXIF Version0220
Supported filetypesJPEG,TIFF
DirectiveLocal ValueMaster Value
exif.decode_jis_intelJISJIS
exif.decode_jis_motorolaJISJIS
exif.decode_unicode_intelUCS-2LEUCS-2LE
exif.decode_unicode_motorolaUCS-2BEUCS-2BE
exif.encode_jisno valueno value
exif.encode_unicodeISO-8859-15ISO-8859-15

fileinfo

fileinfo supportenabled
version1.0.5

filter

Input Validation and Filteringenabled
Revision$Id: 2aa8dd57d9c0c655cd45e6e5872bb95fa5ad76cf $
DirectiveLocal ValueMaster Value
filter.defaultunsafe_rawunsafe_raw
filter.default_flagsno valueno value

ftp

FTP supportenabled

gettext

GetText Supportenabled

gmp

gmp supportenabled
GMP version6.0.0

hash

hash supportenabled
Hashing Enginesmd2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd128 ripemd160 ripemd256 ripemd320 whirlpool tiger128,3 tiger160,3 tiger192,3 tiger128,4 tiger160,4 tiger192,4 snefru snefru256 gost adler32 crc32 crc32b fnv132 fnv164 joaat haval128,3 haval160,3 haval192,3 haval224,3 haval256,3 haval128,4 haval160,4 haval192,4 haval224,4 haval256,4 haval128,5 haval160,5 haval192,5 haval224,5 haval256,5

iconv

iconv supportenabled
iconv implementationglibc
iconv library version2.17
DirectiveLocal ValueMaster Value
iconv.input_encodingISO-8859-1ISO-8859-1
iconv.internal_encodingISO-8859-1ISO-8859-1
iconv.output_encodingISO-8859-1ISO-8859-1

json

json supportenabled
json version1.2.1

libxml

libXML supportactive
libXML Compiled Version2.9.1
libXML Loaded Version20901
libXML streamsenabled

mhash

MHASH supportEnabled
MHASH API VersionEmulated Support

openssl

OpenSSL supportenabled
OpenSSL Library VersionOpenSSL 1.0.1e-fips 11 Feb 2013
OpenSSL Header VersionOpenSSL 1.0.1e-fips 11 Feb 2013

pcre

PCRE (Perl Compatible Regular Expressions) Supportenabled
PCRE Library Version8.32 2012-11-30
DirectiveLocal ValueMaster Value
pcre.backtrack_limit10000001000000
pcre.recursion_limit100000100000

Phar

Phar: PHP Archive supportenabled
Phar EXT version2.0.1
Phar API version1.1.1
SVN revision$Id: c5042cc34acebcc0926625b57dff03deebbe6472 $
Phar-based phar archivesenabled
Tar-based phar archivesenabled
ZIP-based phar archivesenabled
gzip compressionenabled
bzip2 compressionenabled
Native OpenSSL supportenabled
Phar based on pear/PHP_Archive, original concept by Davey Shafik.
Phar fully realized by Gregory Beaver and Marcus Boerger.
Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.
DirectiveLocal ValueMaster Value
phar.cache_listno valueno value
phar.readonlyOnOn
phar.require_hashOnOn

Reflection

Reflectionenabled
Version$Id: 6c4d8062369898a397e4b128348042f5c01b4427 $

session

Session Supportenabled
Registered save handlersfiles user
Registered serializer handlersphp php_binary
DirectiveLocal ValueMaster Value
session.auto_startOffOff
session.cache_expire180180
session.cache_limiternocachenocache
session.cookie_domainno valueno value
session.cookie_httponlyOffOff
session.cookie_lifetime00
session.cookie_path//
session.cookie_secureOffOff
session.entropy_file/dev/urandom/dev/urandom
session.entropy_length3232
session.gc_divisor10001000
session.gc_maxlifetime14401440
session.gc_probability11
session.hash_bits_per_character55
session.hash_function00
session.namePHPSESSIDPHPSESSID
session.referer_checkno valueno value
session.save_handlerfilesfiles
session.save_pathno valueno value
session.serialize_handlerphpphp
session.upload_progress.cleanupOnOn
session.upload_progress.enabledOnOn
session.upload_progress.freq1%1%
session.upload_progress.min_freq11
session.upload_progress.namePHP_SESSION_UPLOAD_PROGRESSPHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefixupload_progress_upload_progress_
session.use_cookiesOnOn
session.use_only_cookiesOnOn
session.use_trans_sid00

shmop

shmop supportenabled

SimpleXML

Simplexml supportenabled
Revision$Id: 692516840b2d7d6e7aedb0bedded1f53b764a99f $
Schema supportenabled

sockets

Sockets Supportenabled

SPL

SPL supportenabled
InterfacesCountable, OuterIterator, RecursiveIterator, SeekableIterator, SplObserver, SplSubject
ClassesAppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException

standard

Dynamic Library Supportenabled
Path to sendmail/usr/sbin/sendmail -t -i
DirectiveLocal ValueMaster Value
assert.active11
assert.bail00
assert.callbackno valueno value
assert.quiet_eval00
assert.warning11
auto_detect_line_endings00
default_socket_timeout6060
fromno valueno value
url_rewriter.tagsa=href,area=href,frame=src,input=src,form=fakeentrya=href,area=href,frame=src,input=src,form=fakeentry
user_agentno valueno value

tokenizer

Tokenizer Supportenabled

xml

XML Supportactive
XML Namespace Supportactive
libxml2 Version2.9.1

zip

Zipenabled
Extension Version$Id: 0c033d4e4613d577409950ed7bf8da4b68286d15 $
Zip version1.11.0
Compiled against libzip version0.10.1

zlib

ZLib Supportenabled
Stream Wrappercompress.zlib://
Stream Filterzlib.inflate, zlib.deflate
Compiled Version1.2.7
Linked Version1.2.7
DirectiveLocal ValueMaster Value
zlib.output_compressionOffOff
zlib.output_compression_level-1-1
zlib.output_handlerno valueno value

Additional Modules

Module Name

Environment

VariableValue
LANGen_US.UTF-8
PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
UNITD_OPTIONS–log /var/log/unitd.log –pid /run/unitd.pid

PHP Variables

VariableValue
_SERVER[“SERVER_PROTOCOL”]HTTP/1.1
_SERVER[“PHP_SELF”]/
_SERVER[“SCRIPT_NAME”]/
_SERVER[“SCRIPT_FILENAME”]/usr/share/doc/unit/examples/php-app/index.php
_SERVER[“DOCUMENT_ROOT”]/usr/share/doc/unit/examples/php-app
_SERVER[“REQUEST_METHOD”]GET
_SERVER[“REQUEST_URI”]/
_SERVER[“SERVER_NAME”]localhost
_SERVER[“SERVER_PORT”]8300
_SERVER[“REMOTE_ADDR”]127.0.0.1
_SERVER[“SERVER_ADDR”]0.0.0.0
_SERVER[“HTTP_USER_AGENT”]curl/7.29.0
_SERVER[“HTTP_HOST”]localhost:8300
_SERVER[“HTTP_ACCEPT”]*/*
_SERVER[“REQUEST_TIME_FLOAT”]1505725162.0346
_SERVER[“REQUEST_TIME”]1505725162

PHP License

This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net.

サンプルを見てもPHPが動作していることがわかります。

これがPythonではこのような動作をします。

# curl http://localhost:8400/
2017-09-18 08:59:29 AM
ENV Variables:
LANG en_US.UTF-8
PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
UNITD_OPTIONS –log /var/log/unitd.log –pid /run/unitd.pid
なお、goはタイムアウト・・・課題ありです。調べておきます。。。。
# curl http://localhost:8500/
Read header timeout
なお、Ubuntuを使う場合は以下の手順になります。

Ubuntu Packages

  1. NGINX、Inc.のリポジトリとパッケージに使用する認証鍵 [key] をダウンロードします。
  2. aptプログラムのキーリングにキーを追加します。
    プログラムはNGINXリポジトリの署名を認証することができ、NGINX Unitパッケージのインストール中にPGPキーが見つからないという警告が表示されなくなります。

     
    # sudo apt-key add nginx_signing.key
  3. /etc/apt/sources.listファイルの末尾に次の行を追加します。
    deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx
    deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx
  4. NGINX Unit パッケージをダウンロードし、インストールします。
    # apt-get update
    # apt-get install unit

NGINX Unitのドキュメント原文はこちらを参照ください。