Instalimi i NGINX nga kodi burimor është relativisht "i lehtë" - shkarkoni versionin më të fundit të kodit burimor NGINX, konfiguroni, ndërtoni dhe instaloni atë.
Instaloni "Mjetet e Zhvillimit" dhe redaktorin Vim:
sudo yum groupinstall -y 'Development Tools' && sudo yum install -y vim
Instaloni paketa shtesë për Enterprise Linux (EPEL):
sudo yum install -y epel-release
Shkarkoni dhe instaloni varësitë opsionale NGINX:
sudo yum install -y perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel GeoIP GeoIP-devel
Shkarkoni versionin më të fundit kryesor të kodit burimor NGINX dhe nxirrni atë:
wget https://nginx.org/download/nginx-1.13.2.tar.gz && tar zxvf nginx-1.13.2.tar.gz
Shkarkoni kodin burimor të varësive NGINX dhe nxirrni ato:
NGINX depends on 3 libraries: PCRE, zlib and OpenSSL:
# PCRE version 8.40
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.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
Hiq të gjithë .tar.gzskedarët. Nuk na duhen më:
rm -rf *.tar.gz
Shkoni te drejtoria e burimit NGINX:
cd ~/nginx-1.13.2
Për masë të mirë, rendisni skedarët dhe drejtoritë e kodit burimor nginx:
ls
# auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
Kopjo faqen manuale NGINX në /usr/share/man/man8:
sudo cp ~/nginx-1.13.2/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
Për ndihmë, mund të rendisni çelësat e disponueshëm të konfigurimit duke ekzekutuar:
./configure --help
# To see want core modules can be build as dynamic run:
./configure --help | grep -F =dynamic
Konfiguroni, përpiloni dhe instaloni 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=CentOS \
--builddir=nginx-1.13.2 \
--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 \
--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.40 \
--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
Symlink /usr/lib64/nginx/modulesnë /etc/nginx/modulesdirektorium, në mënyrë që të mund të ngarkoni module dinamike në konfigurimin nginx si kjo load_module modules/ngx_foo_module.so;:
sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules
Printoni versionin NGINX, versionin e përpiluesit dhe konfiguroni parametrat e skriptit:
sudo nginx -V
# nginx version: nginx/1.13.2 (CentOS)
# built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
# built with OpenSSL 1.1.0f 25 May 2017
# TLS SNI support enabled
# configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx . . .
# . . .
# . . .
Krijo përdoruesin dhe grupin e sistemit NGINX:
sudo useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx
Kontrolloni sintaksën dhe gabimet e mundshme:
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
Krijoni një skedar të njësisë systemd për nginx:
sudo vim /usr/lib/systemd/system/nginx.service
Kopjo/ngjit përmbajtjen e mëposhtme:
NOTE: The location of the PID file and the NGINX binary may be different depending on how NGINX was compiled.
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
Filloni dhe aktivizoni shërbimin NGINX:
sudo systemctl start nginx.service && sudo systemctl enable nginx.service
Kontrolloni nëse NGINX do të fillojë pas një rindezjeje:
sudo systemctl is-enabled nginx.service
# enabled
Kontrolloni nëse NGINX po funksionon:
sudo systemctl status nginx.service
ps aux | grep nginx
curl -I 127.0.0.1
Rinisni VPS-në tuaj për të verifikuar që NGINX fillon automatikisht:
sudo shutdown -r now
Hiq skedarët arkaikë nga /etc/nginxdrejtoria:
sudo rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf
Vendosni theksimin e sintaksës së konfigurimit NGINX për vimnë ~/.vim/. Ju do të merrni një theksim të bukur sintaksor kur redaktoni skedarin e konfigurimit NGINX:
mkdir ~/.vim/
cp -r ~/nginx-1.13.2/contrib/vim/* ~/.vim/
Hiq të gjithë .defaultskedarët rezervë nga /etc/nginx/:
sudo rm /etc/nginx/*.default
Kjo eshte. Tani keni të instaluar versionin më të ri të NGINX. Është përpiluar në mënyrë statike kundër disa bibliotekave të rëndësishme si OpenSSL. Shpesh, versioni OpenSSL i sistemit është i vjetëruar. Duke përdorur këtë metodë të instalimit me një version më të ri të OpenSSL, ju mund të përfitoni nga kodet e reja si CHACHA20_POLY1305dhe protokollet si TLS 1.3 që do të jenë të disponueshme në OpenSSL 1.1.1(i cili nuk është lëshuar në kohën e shkrimit).