Kërkesat për ndërtimin e NGINX nga burimi
Perpara se te fillosh
Ndërtoni NGINX nga burimi
konkluzioni
NGINX mund të përdoret si një server HTTP/HTTPS, server proxy të kundërt, server proxy mail, balancues ngarkese, terminator TLS ose server memorie. Nga dizajni është mjaft modular. Ka module vendase dhe module të palëve të treta të krijuara nga komuniteti. I shkruar në gjuhën e programimit C, është një softuer shumë i shpejtë dhe i lehtë.
NOTE: NGINX has two version streams that run in parallel - stable and mainline. Both versions can be used on a production server. It is recommended to use the mainline version in production.
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ë.
Në këtë tutorial do të përdor versionin kryesor , i cili është 1.13.1 në kohën e shkrimit. Përditësoni numrat e versioneve në përputhje me rrethanat kur versionet më të reja të jenë të disponueshme.
Kërkesat për ndërtimin e NGINX nga burimi
Kërkesat e detyrueshme:
- Versioni i bibliotekës OpenSSL midis 1.0.2 - 1.1.0
- Versioni i bibliotekës Zlib midis 1.1.3 - 1.2.11
- Versioni i bibliotekës PCRE midis 4.4 - 8.40
- Përpiluesi GCC
Kërkesat opsionale:
Perpara se te fillosh
Krijo përdorues të rregullt me sudoakses .
Kalo te përdoruesi i ri:
su - <username>
Sistemi i përditësimit:
sudo apt update && sudo apt upgrade -y
Ndërtoni NGINX nga burimi
NGINX është një program i shkruar në C, kështu që ne duhet të instalojmë përpiluesin C (GCC).
sudo apt install build-essential -y
Shkarkoni versionin më të fundit të kodit burimor NGINX dhe nxirrni atë:
wget https://nginx.org/download/nginx-1.13.1.tar.gz && tar zxvf nginx-1.13.1.tar.gz
Shkarkoni kodin burimor të varësive NGINX dhe nxirrni ato:
NGINX depends on 3 libraries: PCRE, zlib and OpenSSL:
# PCRE version 4.4 - 8.40
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz && tar xzvf pcre-8.40.tar.gz
# zlib version 1.1.3 - 1.2.11
wget http://www.zlib.net/zlib-1.2.11.tar.gz && tar xzvf zlib-1.2.11.tar.gz
# OpenSSL version 1.0.2 - 1.1.0
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.1
Për ndihmë, mund të listoni çelësat e disponueshëm të konfigurimit duke ekzekutuar:
./configure --help
Konfiguroni, përpiloni dhe instaloni NGINX:
./configure --prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=www-data \
--group=www-data \
--build=Ubuntu \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--with-openssl=../openssl-1.1.0f \
--with-openssl-opt=enable-ec_nistp_64_gcc_128 \
--with-openssl-opt=no-nextprotoneg \
--with-openssl-opt=no-weak-ssl-ciphers \
--with-openssl-opt=no-ssl3 \
--with-pcre=../pcre-8.40 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_secure_link_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-debug \
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now'
make
sudo make install
Hiqni të gjithë skedarët e shkarkuar nga drejtoria kryesore, në këtë rast /home/username:
cd ~
rm -r nginx-1.13.1/ openssl-1.1.0f/ pcre-8.40/ zlib-1.2.11/
Kontrolloni versionin NGINX dhe përpiloni opsionet e kohës:
sudo nginx -v && sudo nginx -V
# nginx version: nginx/1.13.0 (Ubuntu)
# built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
# built with OpenSSL 1.1.0f 25 May 2017
# TLS SNI support enabled
# configure arguments: --prefix=/etc/nginx . . .
# . . .
# . . .
Kontrolloni sintaksën dhe gabimet e mundshme:
sudo nginx -t
# Will throw this error nginx: [emerg] mkdir() "/var/lib/nginx/body" failed (2: No such file or directory)
# Just create directory
mkdir -p /var/lib/nginx && sudo nginx -t
Krijo një skedar systemd për NGINX:
sudo vim /etc/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=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/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 /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[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 Ubuntu VPS-në tuaj për të verifikuar që NGINX fillon automatikisht:
sudo shutdown -r now
Krijo profilin e aplikacionit UFW NGINX:
sudo vim /etc/ufw/applications.d/nginx
Kopjo/ngjit përmbajtjen e mëposhtme:
[Nginx HTTP]
title=Web Server (Nginx, HTTP)
description=Small, but very powerful and efficient web server
ports=80/tcp
[Nginx HTTPS]
title=Web Server (Nginx, HTTPS)
description=Small, but very powerful and efficient web server
ports=443/tcp
[Nginx Full]
title=Web Server (Nginx, HTTP + HTTPS)
description=Small, but very powerful and efficient web server
ports=80,443/tcp
Tani, verifikoni që profilet e aplikacionit UFW janë krijuar dhe njohur:
sudo ufw app list
# Available applications:
# Nginx Full
# Nginx HTTP
# Nginx HTTPS
# OpenSSH
konkluzioni
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ë instalimi 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).