Instaliranje NGINX-a iz izvornog koda je relativno "jednostavno" - preuzmite najnoviju verziju izvornog koda NGINX-a, konfigurirajte ga, izgradite i instalirajte.
Instalirajte "Alati za razvoj", Vim editor, wget i gcc-c++:
sudo dnf install -y @development-tools && sudo dnf install -y vim wget gcc-c++
Preuzmite najnoviju glavnu verziju izvornog koda NGINX i raspakirajte ga:
wget https://nginx.org/download/nginx-1.13.3.tar.gz && tar zxvf nginx-1.13.3.tar.gz
Preuzmite izvorni kod NGINX ovisnosti i raspakirajte ih:
NGINX depends on 3 libraries: PCRE, zlib and OpenSSL:
# PCRE version 8.41
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz && tar xzvf pcre-8.41.tar.gz
# zlib version 1.2.11
wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz
# OpenSSL version 1.1.0f
wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz && tar xzvf openssl-1.1.0f.tar.gz
Preuzmite i instalirajte izborne NGINX ovisnosti:
# perl
sudo dnf install -y perl perl-devel perl-ExtUtils-Embed
# libxslt
sudo dnf install -y libxslt libxslt-devel
# libxml2
sudo dnf install -y libxml2 libxml2-devel
# libgd
sudo dnf install -y gd gd-devel
# GeoIP
sudo dnf install -y GeoIP GeoIP-devel
# Libatomic_Ops
sudo dnf install -y libatomic_ops libatomic_ops-devel
Uklonite sve .tar.gzdatoteke. Ne trebaju nam više:
rm -rf *.tar.gz
Idite na izvorni direktorij NGINX:
cd ~/nginx-1.13.3
Za dobru mjeru, navedite datoteke i direktorije NGINX izvornog koda:
ls
# auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
Kopirajte stranicu priručnika za NGINX na /usr/share/man/man8/:
sudo cp ~/nginx-1.13.3/man/nginx.8 /usr/share/man/man8/
sudo gzip /usr/share/man/man8/nginx.8
# Check that Man page for NGINX is working
man nginx
Za pomoć možete navesti dostupne konfiguracijske sklopke tako da pokrenete:
./configure --help
# To see want core modules can be build as dynamic run:
./configure --help | grep -F =dynamic
Konfigurirajte, kompajlirajte i instalirajte NGINX:
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=Fedora \
--builddir=nginx-1.13.3 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--with-perl=/usr/bin/perl \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.41 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.0f \
--with-openssl-opt=no-nextprotoneg \
--with-debug
make
sudo make install
Ispišite verziju NGINX-a, verziju prevoditelja i konfigurirajte parametre skripte:
nginx -V
# nginx version: nginx/1.13.3 (Fedora)
# built by gcc 6.3.1 20161221 (Red Hat 6.3.1-1) (GCC)
# built with OpenSSL 1.1.0f 25 May 2017
# TLS SNI support enabled
# configure arguments: --prefix=/etc/nginx . . .
# . . .
Kreirajte korisnika i grupu NGINX sustava:
sudo useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx
Provjerite sintaksu i moguće pogreške:
sudo nginx -t
# Will throw this error: nginx: [emerg] mkdir() "/var/cache/nginx/client_temp" failed (2: No such file or directory)
# Just create directory
sudo mkdir -p /var/cache/nginx/ && sudo nginx -t
Napravite systemd jediničnu datoteku za NGINX:
sudo vim /etc/systemd/system/nginx.service
Kopirajte/zalijepite sljedeći sadržaj:
NOTE: The location of the PID file and the NGINX binary may be different depending on how NGINX was compiled.
[Unit]
Description=Nginx - A high performance web server and a reverse proxy server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
Pokrenite NGINX:
sudo systemctl start nginx.service
Omogućite NGINX da se automatski pokrene pri pokretanju:
sudo systemctl enable nginx.service
Provjerite hoće li se NGINX pokrenuti nakon ponovnog pokretanja:
sudo systemctl is-enabled nginx.service
# enabled
Provjerite radi li NGINX:
sudo systemctl status nginx.service
ps aux | grep nginx
curl -I 127.0.0.1
Ponovno pokrenite svoj VPS da biste provjerili da se NGINX automatski pokreće:
sudo shutdown -r now
Uklonite arhaične datoteke iz /etc/nginx/direktorija:
sudo rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf
Stavite datoteke za isticanje sintakse NGINX konfiguracije za vimu ~/.vim/. Bit će vam predstavljeno lijepo isticanje sintakse prilikom uređivanja NGINX konfiguracijske datoteke:
mkdir ~/.vim/
cp -r ~/nginx-1.13.3/contrib/vim/* ~/.vim/
Napravite conf.d/imenik u /etc/nginx/imeniku. U ovaj direktorij možete postaviti virtualne poslužitelje i upstreamove:
sudo mkdir /etc/nginx/conf.d/
Uklonite ekstrahirane direktorije i datoteke iz vašeg matičnog direktorija:
rm -rf nginx-1.13.3/ openssl-1.1.0f/ pcre-8.41/ zlib-1.2.11/
To je to. Sada imate instaliranu najnoviju verziju NGINX-a. Sastavlja se statički prema nekim važnim knjižnicama poput OpenSSL-a. Često je verzija sustava OpenSSL zastarjela. Korištenjem ove metode instaliranja s novijom verzijom OpenSSL-a, možete iskoristiti prednosti novih šifri poput CHACHA20_POLY1305i protokola poput TLS-a 1.3 koji će biti dostupni u OpenSSL-u 1.1.1(koji nije bio objavljen u vrijeme pisanja).