Nginx编译与WebUI
非基础Nginx操作
最新Nginx版本安装
通过接入PPA,获取最新Nginx版本
# 1. 安装必要工具
sudo apt install software-properties-common
# 2. 添加 PPA(稳定版 1.26+,包含 1.24 功能)
sudo add-apt-repository ppa:ondrej/nginx
# 创建优先级配置文件,不然会默认安装ubuntu源的版本
sudo tee /etc/apt/preferences.d/ondrej-nginx > /dev/null <<EOF
Package: nginx nginx-common nginx-core libnginx-mod-*
Pin: release o=LP-PPA-ondrej-nginx
Pin-Priority: 1001
Package: *
Pin: release o=LP-PPA-ondrej-nginx
Pin-Priority: 500
EOF
# 3. 更新并安装
sudo apt update
sudo apt upgrade
# 4. 安装额外模块(如需要)
sudo apt install libnginx-mod-http-headers-more-filter \
libnginx-mod-http-geoip2 \
libnginx-mod-stream-geoip2
动态模块加载
参考:服务监控 - Nginx-vts-exporter小节
Nginx编译安装 - 费力
apt-get install nginx
apt-cache search libnginx
apt-get install libnginx-mod-http-geoip2 libnginx-mod-http-headers-more-filter libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2
mkdir webapps
apt-get update
apt-get upgrade
apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev curl git
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module
git clone https://github.com/leev/ngx_http_geoip2_module.git
apt-get install libmaxminddb0 libmaxminddb-dev
nginx -V
cd nginx-1.18.0/
patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
./configure --with-cc-opt='-g -O2 -ffile-prefix-map=/build/nginx-niToSo/nginx-1.18.0=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/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=/run/nginx.pid --modules-path=/usr/lib/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 --with-compat --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --add-dynamic-module=../ngx_http_geoip2_module --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_sub_module --add-dynamic-module=../ngx_http_proxy_connect_module --with-cc-opt="-Wno-deprecated-declarations"
make
cd /usr/sbin/
ll nginx
mv nginx nginx.bak
cp /opt/nginx-1.18.0/objs/nginx ./
NginxWebUI
启动命令
#!/bin/bash
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java \
-jar -Dfile.encoding=UTF-8 /opt/nginxWebUI/nginxWebUI.jar \
--server.port=8080 \
--project.home=/opt/nginxWebUI/ \
--spring.database.type=mysql \
--spring.datasource.url=jdbc:mysql://192.168.1.5:3306/nginxwebui \
--spring.datasource.username=root \
--spring.datasource.password=****** \
>/dev/null 2>&1
停止命令
#!/bin/sh
pid=$(ps -ef | grep nginxWebUI.jar | grep -v grep | awk '{print $2}')
if [ ! $pid ]; then
echo "nginxWebUI.jar is not running"
exit 0
fi
kill -9 $pid
nginx配置
server {
server_name www.youcats.cn;
listen 14700 ssl http2;
listen [::]:14700 ssl http2;
ssl_certificate /opt/webapps/ssl-docs/youcats.cn/youcats.cn_bundle.crt;
ssl_certificate_key /opt/webapps/ssl-docs/youcats.cn/youcats.cn.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Headers *;
add_header Access-Control-Allow-Credentials true;
if ($request_method = 'OPTIONS') {
return 204;
}
}
}
Nginx编译与WebUI
https://www.youcats.cn/archives/1770265040239
评论