Что же делать, если нам необходимо добавить какой-либо модуль? Правильно, нужно пересобрать nginx вручную. О том как это правильно сделать в Linux написано в данной статье.
Предположим, для примера, что нам необходимо добавить в nginx модуль http_mp4_module. Вывод команды nginx -V покажет нам, что nginx собран без него.
Код: Выделить всё
# nginx -V
Код: Выделить всё
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
Код: Выделить всё
# wget http://nginx.org/download/nginx-1.2.1.tar.gz
Код: Выделить всё
# tar –xvf nginx-1.2.1.tar.gz
# cd nginx-1.2.1
Для Debian/Ubuntu выполняем:
Код: Выделить всё
# aptitude install build-essential
Код: Выделить всё
# yum install gcc gcc-c++ kernel-devel
# yum groupinstall 'Development Tools'
Для этого копируем из текстового редактора вывод команды 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
Код: Выделить всё
./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: 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.
Код: Выделить всё
# aptitude install libpcre++-dev
Код: Выделить всё
# yum install 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.
Код: Выделить всё
# aptitude install libssl-dev
Код: Выделить всё
# yum install openssl-devel
Код: Выделить всё
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.
Код: Выделить всё
# aptitude install libgeoip-dev
Код: Выделить всё
# yum install GeoIP-devel
Код: Выделить всё
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
Код: Выделить всё
# aptitude install libxslt1-dev
Код: Выделить всё
# yum install libxslt-devel
Код: Выделить всё
./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"
Код: Выделить всё
# make
# make install
Код: Выделить всё
# /etc/nginx/sbin/nginx -V
Код: Выделить всё
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:
Код: Выделить всё
# service nginx stop
Код: Выделить всё
# mv /usr/sbin/nginx /usr/sbin/nginx_back
Код: Выделить всё
# mv /etc/nginx/sbin/nginx /usr/sbin/nginx
Код: Выделить всё
# rm -r -f /etc/nginx/sbin
Код: Выделить всё
# nginx -V
Код: Выделить всё
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
Код: Выделить всё
# service nginx start
Код: Выделить всё
# cd ../
# rm -r -f nginx-1.2.1