Last active
March 18, 2024 13:23
-
-
Save manti-by/f7c1e02187641391fb558f83ade08d5d to your computer and use it in GitHub Desktop.
Install NGINX 1.25 with brottli and header more modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo adduser --disabled-password --gecos "" nginx | |
git clone --recurse-submodules git@github.com:google/ngx_brotli.git | |
cd ngx_brotli/deps/brotli/ && mkdir out && cd out | |
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -m64 -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_INSTALL_PREFIX=./installed .. | |
cmake --build . --config Release --target brotlienc && cd ../../../../ | |
git clone git@github.com:openresty/headers-more-nginx-module.git ngx_headers_more | |
sudo apt install -y libpcre3-dev libssl-dev zlib1g-dev | |
wget https://nginx.org/download/nginx-1.25.3.tar.gz | |
tar -xzf nginx-1.25.3.tar.gz && rm -rf nginx-1.25.3.tar.gz && cd nginx-1.25.3/ | |
./configure --add-module=../ngx_headers_more/ --add-module=../ngx_brotli/ \ | |
--with-http_ssl_module --with-http_v2_module --with-http_v3_module \ | |
--with-pcre --with-stream=dynamic \ | |
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx \ | |
--conf-path=/etc/nginx/nginx.conf \ | |
--http-log-path=/var/log/nginx/access.log \ | |
--error-log-path=/var/log/nginx/error.log \ | |
--lock-path=/var/lock/nginx.lock \ | |
--pid-path=/var/run/nginx.pid \ | |
--modules-path=/etc/nginx/modules \ | |
--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 | |
make -j2 && sudo make install | |
sudo vim /lib/systemd/system/nginx.service | |
sudo systemctl enable nginx.service | |
sudo systemctl start nginx.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log notice; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 65; | |
types_hash_max_size 2048; | |
server_tokens off; | |
ssl_protocols TLSv1.2 TLSv1.3; | |
ssl_prefer_server_ciphers on; | |
brotli on; | |
brotli_comp_level 6; | |
brotli_static on; | |
brotli_types application/atom+xml application/javascript application/json application/vnd.api+json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype font/woff font/woff2 image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml; | |
more_set_headers 'server: amon-ra 3.1.0'; | |
include /etc/nginx/conf.d/*.conf; | |
include /etc/nginx/sites-enabled/*; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 | |
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf | |
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)" | |
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)" | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment