При установке nginx штатными средствами ОС в Linux (apt-get, aptitude, yum) нет возможности сконфигурировать его установку, чтобы добавить или убрать какие-либо модули и nginx устанавливается "как есть".
Что же делать, если нам необходимо добавить какой-либо модуль? Правильно, нужно пересобрать nginx вручную. О том как это правильно сделать в Linux написано в данной статье.
Предположим, для примера, что нам необходимо добавить в nginx модуль http_mp4_module. Вывод команды
nginx -V покажет нам, что nginx собран без него.
Результат:
Код: Виділити все
nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --without-http_geo_module --without-http_limit_req_module --without-http_limit_zone_module
--without-http_memcached_module --without-http_referer_module --without-http_scgi_module --without-http_split_clients_module
--with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_uwsgi_module
--add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-echo
Сохраним вывод команды
nginx -V в какой-нибудь текстовый редактор - эта информация нам пригодится при конфигурировании. Видим, что версия nginx у нас установлена 1.2.1 - скачиваем такую же версию:
Код: Виділити все
# wget http://nginx.org/download/nginx-1.2.1.tar.gz
Распакуем архив и перейдём в папку nginx-1.2.1:
Код: Виділити все
# tar –xvf nginx-1.2.1.tar.gz
# cd nginx-1.2.1
Далее, для сборки, нам потребуется установить в систему дополнительные пакеты.
Для Debian/Ubuntu выполняем:
Для CentOS выполняем:
Код: Виділити все
# yum install gcc gcc-c++ kernel-devel
# yum groupinstall 'Development Tools'
После установки пакетов приступаем к конфигурированию nginx с добавлением модуля http_mp4_module.
Для этого копируем из текстового редактора вывод команды
nginx -V начиная с
--prefix= и до первого
--add-module= (все присутствующие в выводе
--add_module= нам не нужны). После чего пишем в консоли ./configure и вставляем скопированное из редактора. Должно получиться так:
Код: Виділити все
./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module
В конец строки добавляем
--with-http_mp4_module чтобы получилось так:
Код: Виділити все
./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module
Нажимаем Enter и ждём окончания процесса.
--------
В процессе конфигурирования возможно будут появляться ошибки. Способы их устранения описаны ниже.
Ошибка:
Код: Виділити все
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
Для Debian/Ubuntu исправляется установкой libpcre++-dev:
Для CentOS исправляется установкой pcre-devel:
Ошибка:
Код: Виділити все
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
Для Debian/Ubuntu:
Для CentOS:
Ошибка:
Код: Виділити все
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.
Для Debian/Ubunru:
Для CentOS:
Ошибка:
Код: Виділити все
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
Для Debian/Ubunru:
Для CentOS:
Каждый раз после
aptitude install или
yum install недостающего пакета запускаем заново
Код: Виділити все
./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module
-----------
После успешного окончания конфигурирования увидим на экране что-то вроде:
Код: Виділити все
nginx path prefix: "/etc/nginx"
nginx binary file: "/etc/nginx/sbin/nginx"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/lib/nginx/body"
nginx http proxy temporary files: "/var/lib/nginx/proxy"
nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
Теперь можно собрать бинарник nginx - выполняем 2 команды:
По окончании сборки проверяем, что nginx собрался с нужным нам модулем:
Результат:
Код: Виділити все
nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module
Как видим,
--with-http_mp4_module в выводе команды присутствует - всё получилось. Осталось заменить текущий бинарник nginx новым, который мы только что собрали.
Останавливаем nginx:
Переименовываем (на всякий случай) текущий nginx в
nginx_back:
Перемещаем на его место новый собраный бинарник:
Удаляем ненужную больше папку
/etc/nginx/sbin:
Проверяем ещё раз, что nginx у нас теперь тот, что нужно:
Результат:
Код: Виділити все
nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module
Запускаем nginx:
Удаляем ненужную больше папку nginx-1.2.1:
Источник: Добавление модулей nginx в Linux (Debian/Ubuntu/CentOS)
При установке nginx штатными средствами ОС в Linux (apt-get, aptitude, yum) нет возможности сконфигурировать его установку, чтобы добавить или убрать какие-либо модули и nginx устанавливается "как есть".
Что же делать, если нам необходимо добавить какой-либо модуль? Правильно, нужно пересобрать nginx вручную. О том как это правильно сделать в Linux написано в данной статье.
Предположим, для примера, что нам необходимо добавить в nginx модуль http_mp4_module. Вывод команды [b]nginx -V[/b] покажет нам, что nginx собран без него.
[code]# nginx -V[/code]
Результат:
[code]nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --without-http_geo_module --without-http_limit_req_module --without-http_limit_zone_module
--without-http_memcached_module --without-http_referer_module --without-http_scgi_module --without-http_split_clients_module
--with-http_stub_status_module --without-http_ssi_module --without-http_userid_module --without-http_uwsgi_module
--add-module=/tmp/buildd/nginx-1.2.1/debian/modules/nginx-echo[/code]
Сохраним вывод команды [b]nginx -V[/b] в какой-нибудь текстовый редактор - эта информация нам пригодится при конфигурировании. Видим, что версия nginx у нас установлена 1.2.1 - скачиваем такую же версию:
[code]# wget http://nginx.org/download/nginx-1.2.1.tar.gz[/code]
Распакуем архив и перейдём в папку nginx-1.2.1:
[code]# tar –xvf nginx-1.2.1.tar.gz
# cd nginx-1.2.1[/code]
Далее, для сборки, нам потребуется установить в систему дополнительные пакеты.
Для Debian/Ubuntu выполняем:
[code]# aptitude install build-essential[/code]
Для CentOS выполняем:
[code]# yum install gcc gcc-c++ kernel-devel
# yum groupinstall 'Development Tools'[/code]
После установки пакетов приступаем к конфигурированию nginx с добавлением модуля http_mp4_module.
Для этого копируем из текстового редактора вывод команды [b]nginx -V[/b] начиная с [b]--prefix=[/b] и до первого [b]--add-module=[/b] (все присутствующие в выводе [b]--add_module=[/b] нам не нужны). После чего пишем в консоли ./configure и вставляем скопированное из редактора. Должно получиться так:
[code]./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module[/code]
В конец строки добавляем [b]--with-http_mp4_module[/b] чтобы получилось так:
[code]./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module[/code]
Нажимаем Enter и ждём окончания процесса.
--------
В процессе конфигурирования возможно будут появляться ошибки. Способы их устранения описаны ниже.
Ошибка:
[code]./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.[/code]
Для Debian/Ubuntu исправляется установкой libpcre++-dev:
[code]# aptitude install libpcre++-dev[/code]
Для CentOS исправляется установкой pcre-devel:
[code]# yum install pcre-devel[/code]
Ошибка:
[code]./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.[/code]
Для Debian/Ubuntu:
[code]# aptitude install libssl-dev[/code]
Для CentOS:
[code]# yum install openssl-devel[/code]
Ошибка:
[code]./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.[/code]
Для Debian/Ubunru:
[code]# aptitude install libgeoip-dev[/code]
Для CentOS:
[code]# yum install GeoIP-devel[/code]
Ошибка:
[code]./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.[/code]
Для Debian/Ubunru:
[code]# aptitude install libxslt1-dev[/code]
Для CentOS:
[code]# yum install libxslt-devel[/code]
Каждый раз после [b]aptitude install[/b] или [b]yum install[/b] недостающего пакета запускаем заново
[code]./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module[/code]
-----------
После успешного окончания конфигурирования увидим на экране что-то вроде:
[code] nginx path prefix: "/etc/nginx"
nginx binary file: "/etc/nginx/sbin/nginx"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/lib/nginx/body"
nginx http proxy temporary files: "/var/lib/nginx/proxy"
nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"[/code]
Теперь можно собрать бинарник nginx - выполняем 2 команды:
[code]# make
# make install[/code]
По окончании сборки проверяем, что nginx собрался с нужным нам модулем:
[code]# /etc/nginx/sbin/nginx -V[/code]
Результат:
[code]nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module[/code]
Как видим, [b]--with-http_mp4_module[/b] в выводе команды присутствует - всё получилось. Осталось заменить текущий бинарник nginx новым, который мы только что собрали.
Останавливаем nginx:
[code]# service nginx stop[/code]
Переименовываем (на всякий случай) текущий nginx в [b]nginx_back[/b]:
[code]# mv /usr/sbin/nginx /usr/sbin/nginx_back[/code]
Перемещаем на его место новый собраный бинарник:
[code]# mv /etc/nginx/sbin/nginx /usr/sbin/nginx[/code]
Удаляем ненужную больше папку [b]/etc/nginx/sbin[/b]:
[code]# rm -r -f /etc/nginx/sbin[/code]
Проверяем ещё раз, что nginx у нас теперь тот, что нужно:
[code]# nginx -V[/code]
Результат:
[code]nginx version: nginx/1.2.1
TLS SNI support enabled
configure arguments: ./configure --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid --with-pcre-jit --with-http_gzip_static_module --with-http_ssl_module --with-ipv6
--without-http_browser_module --with-http_geoip_module --without-http_memcached_module --without-http_referer_module
--without-http_scgi_module --without-http_split_clients_module --with-http_stub_status_module --without-http_ssi_module
--without-http_userid_module --without-http_uwsgi_module --with-http_mp4_module[/code]
Запускаем nginx:
[code]# service nginx start[/code]
Удаляем ненужную больше папку nginx-1.2.1:
[code]# cd ../
# rm -r -f nginx-1.2.1[/code]
[right][i]Источник: [url=http://firstwiki.ru/index.php/%D0%94%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BC%D0%BE%D0%B4%D1%83%D0%BB%D0%B5%D0%B9_nginx_%D0%B2_Linux_(Debian/Ubuntu/CentOS)]Добавление модулей nginx в Linux (Debian/Ubuntu/CentOS)[/url][/i][/right]