OpenSSL 3.5.1 默认仅在较新的 Linux 发行版中可用,例如 Debian 13,本文以 Debian 13 为例进行演示。如果您使用的是较旧的发行版,可能需要手动编译 OpenSSL 3.5.1 或升级您的操作系统。
安装依赖
# Debian 13
apt update
apt install build-essential ca-certificates zlib1g-dev libpcre2-dev tar unzip libssl-dev wget curl git cmake ninja-build libunwind-dev pkg-config libxml2-dev libxslt1-dev libgd-dev libgeoip-dev libperl-dev
安装 brotli 压缩
不需要请跳过,并在编译时删除–add-module=../ngx_brotli
git clone --recurse-submodules -j8 https://github.com/google/ngx_brotli
cd ngx_brotli/deps/brotli
mkdir out && cd out
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS="-Ofast -march=native -mtune=native -flto -funroll-loops -ffunction-sections -fdata-sections -Wl,--gc-sections" -DCMAKE_CXX_FLAGS="-Ofast -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 ../../../..
编译安装quic
注意:
本人是直接在 /root 目录下编译的,如果你在其他目录下,请自行修改路径;
如果你不需要 brotli 压缩,请删除–add-module=../ngx_brotli
本人将 Nginx 安装在 /www/server/nginx 目录下,如果你需要修改,请自行修改路径;
git clone https://github.com/nginx/nginx.git
cd nginx
./auto/configure \
--prefix=/www/server/nginx \
--user=www-data \
--group=www-data \
--with-debug \
--with-http_v3_module \
--with-cc-opt='-g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now' \
--add-module=../ngx_brotli \
--with-compat \
--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 \
--with-http_addition_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_secure_link_module \
--with-http_sub_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module
make
make install
添加 www 用户
大部分系统下默认存在着www-data用户组和www-data用户,如果没有请执行以下命令添加。
groupadd www-data
useradd -g www-data -s /sbin/nologin www-data
添加进程管理
本人使用的是 systemd,如果你使用的是其他进程管理,请自行修改
vim /usr/lib/systemd/system/nginx.service
输入如下内容:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/www/server/nginx/sbin/nginx
ExecReload=/www/server/nginx/sbin/nginx -s reload
ExecStop=/www/server/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动
systemctl start nginx
开机自启
systemctl enable nginx
配置文件
示例配置文件如下,更多特性请参考官方文档:https://nginx.org/en/docs/http/ngx_http_v3_module.html
server {
listen 443 ssl;
listen [::]:443 ssl;
# 用于支持Quic或
listen 443 quic reuseport;
listen [::]:443 quic reuseport;
# 启用 HTTP/3(默认是启用的,所以可以省略这行)
http3 on;
# 用以支持HTTP/2
http2 on;
server_name r2wind.cn;
# Quic或HTTP/3响应头
add_header Alt-Svc 'h3=":443"; ma=86400';
# HSTS
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
location / {
root /www/wwwroot/r2wind.cn;
index index.html index.htm;
}
# 证书配置
ssl_certificate /root/.acme.sh/smb.wiki/fullchain.cer;
ssl_certificate_key /root/.acme.sh/smb.wiki/smb.wiki.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
}
配置完成后,重载 Nginx 即可生效
systemctl reload nginx

评论列表 (0条):
加载更多评论 Loading...