找回密码
 立即注册
CeraNetworksBGVM服务器主机交流IP归属甄别会员请立即修改密码
查看: 86|回复: 9

【分享】Debian 12 的 nginx

[复制链接]

62

主题

786

回帖

2764

积分

金牌会员

积分
2764
发表于 2023-5-22 14:51:43 | 显示全部楼层 |阅读模式
本帖最后由 dvbhack 于 2023-5-22 15:28 编辑

Debian 12 即将于 2023年06月30日发布,目前我暂时升级了 AMD64 和 ARM64 各一台进行前期准备,为之后把所有机器升级到 Debian 12 做准备。

升级的过程中发现 Nginx 官方源还没有提供 Debian 12 的支持,当然,我的 NGINX 也正好一直都是做单独编译后打包 deb 复用的。

这次做完顺手分享一下吧。虽然有需求的 mjj 应该是少数(大部分都会选择自己编译、官方源安装、宝塔和一键脚本)。

deb 下载地址:https://www.aliyundrive.com/s/gerPBhs4NPe

包是可以下载到本机进行解压查看的,如果想使用又担心的,可以先下载到本地解压缩,就能看到这个 deb 包安装时执行的全部命令和向你的系统添加的文件。

安装步骤:

- 先安装依赖项[ol]
  • apt install libjemalloc2[/ol]复制代码
    - 安装 nginx:[ol]
  • dpkg -i nginx-quic_1.25.0_....deb[/ol]复制代码

    =====

    编译说明:

  • 采用 nginx 官方的 nginx-quic 分支(1.25.0),cloudflare 的优化版 zlib,google 的 boringssl(为了支持 quic、http3),pcre2
  • 编译了 image-filter 模块、geoip 模块、njs 模块(支持 nginx 配置文件中使用 javascript,看官方文档)、xslt_filter 模块 为动态模块,可以按需加载
  • 添加了 google 提供的 brotli 模块、openresty 开发的 headers-more 模块为内置模块
  • 增加了 ssl.conf、proxy.conf、fastcgi.conf 和 map.conf 几个常见的配置代码块,减少配置时的重复代码


    编译参数:
    [ol]

  • nginx version: nginx/1.25.0
  • built by gcc 12.2.0 (Debian 12.2.0-14)
  • built with OpenSSL 1.1.1 (compatible; BoringSSL) (running with BoringSSL)
  • TLS SNI support enabled
  • configure arguments: --prefix=/etc/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=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --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 --user=www --group=www --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_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-stream_geoip_module=dynamic --add-dynamic-module=../njs/nginx --add-module=../ngx-brotli --add-module=../ngx-headers-more --with-http_v3_module --with-pcre --with-pcre=../pcre2 --with-pcre-jit --with-zlib=../cf-zlib --with-zlib-opt='-O2 -march=native -fPIC -I/usr/local/src/boringssl/.openssl/include/' --with-zlib-asm=arm64 --with-openssl=../boringssl --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128' --with-cc-opt='-g0 -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -march=native -pipe -flto -funsafe-math-optimizations --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -DTCP_FASTOPEN=23 -I/usr/local/src/boringssl/.openssl/include/' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC -L/usr/local/src/boringssl/.openssl/lib/ -ljemalloc'
  • [/ol]复制代码
  • 回复

    使用道具 举报

    5

    主题

    136

    回帖

    519

    积分

    高级会员

    积分
    519
    发表于 2023-5-22 14:55:20 | 显示全部楼层
    好!支持大佬
    回复

    使用道具 举报

    50

    主题

    587

    回帖

    2170

    积分

    金牌会员

    积分
    2170
    发表于 2023-5-22 15:03:18 | 显示全部楼层
    支持大佬。quic是不是还不支持ssl_preread?
    回复

    使用道具 举报

    472

    主题

    744

    回帖

    3414

    积分

    论坛元老

    积分
    3414
    发表于 2023-5-22 15:05:47 | 显示全部楼层
    泰库辣
    回复

    使用道具 举报

    62

    主题

    786

    回帖

    2764

    积分

    金牌会员

    积分
    2764
     楼主| 发表于 2023-5-22 15:17:04 | 显示全部楼层
    本帖最后由 dvbhack 于 2023-5-22 15:19 编辑

    diocat 发表于 2023-5-22 15:03

    支持大佬。quic是不是还不支持ssl_preread?


    ssl_prepead 是用于 stream 的吧?

    我没试过在 stream 中使用 quic,你可以试试看。我编译的参数是加入了 "-with-stream_ssl_preread_module" 这个选项的。
    回复

    使用道具 举报

    50

    主题

    587

    回帖

    2170

    积分

    金牌会员

    积分
    2170
    发表于 2023-5-22 15:03:00 | 显示全部楼层

    dvbhack 发表于 2023-5-22 15:17

    ssl_prepead 是用于 stream 的吧?

    我没试过在 stream 中使用 quic,你可以试试看。我编译的参数是加入 ...


    是的。之前我编的版本加入了module,但是quic下配置ssl_preread on 就直接nginx -t报错,现在不知道行不行
    回复

    使用道具 举报

    62

    主题

    786

    回帖

    2764

    积分

    金牌会员

    积分
    2764
     楼主| 发表于 2023-5-22 15:28:41 | 显示全部楼层

    diocat 发表于 2023-5-22 15:28

    是的。之前我编的版本加入了module,但是quic下配置ssl_preread on 就直接nginx -t报错,现在不知道行不 ...
    [ol]

  • stream {
  •         map $ssl_preread_server_name $name {
  •                 bitbucket.net bitbucket;
  •                 gitlab.com gitlab;
  •                 default github;
  •         }

  •         upstream github {
  •                 server 20.205.243.166:443;
  •         }

  •         upstream bitbucket {
  •                 server 104.192.141.1:443;
  •         }

  •         upstream gitlab {
  •                 server 172.65.251.78:443;
  •         }

  •         server {
  •                 listen 8443;
  •                 proxy_pass $name;
  •                 ssl_preread on;
  •         }

  •         server {
  •                 listen 8443 udp;
  •                 proxy_pass $name;
  •                 ssl_preread on;
  •         }
  • }
  • [/ol]复制代码

    stream 是4层转发,它只是把指定端口的请求转发给 upstream,对它来说,不需要区分是 http2 还是 http3,顶多区分一下 tcp、udp 吧?

    我测试了上面的配置:
    [ol]

  • $ nginx -t
  • nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  • nginx: configuration file /etc/nginx/nginx.conf test is successful

  • $ systemctl restart nginx
  • $

  • $ netstat -anl | grep 8443
  • tcp        0      0 0.0.0.0:8443            0.0.0.0:*               LISTEN
  • udp        0      0 0.0.0.0:8443            0.0.0.0:*
  • [/ol]复制代码

    看起来没有什么问题。
  • 回复

    使用道具 举报

    21

    主题

    184

    回帖

    1245

    积分

    金牌会员

    积分
    1245
    发表于 2023-5-22 15:17:00 | 显示全部楼层
    支持大佬 zsbd
    回复

    使用道具 举报

    62

    主题

    786

    回帖

    2764

    积分

    金牌会员

    积分
    2764
     楼主| 发表于 2023-5-22 15:47:17 | 显示全部楼层

    diocat 发表于 2023-5-22 15:28

    是的。之前我编的版本加入了module,但是quic下配置ssl_preread on 就直接nginx -t报错,现在不知道行不 ...
    [ol]

  • curl -i -v --alt-svc altsvc.cache https://github.com:8443/ --resolve github.com:8443:127.0.0.1
  • * Added github.com:8443:127.0.0.1 to DNS cache
  • * Hostname github.com was found in DNS cache
  • *   Trying 127.0.0.1:8443...
  • * Connected to github.com (127.0.0.1) port 8443 (#0)
  • * ALPN: offers h2,http/1.1
  • * TLSv1.3 (OUT), TLS handshake, Client hello (1):
  • *  CAfile: /etc/ssl/certs/ca-certificates.crt
  • *  CApath: /etc/ssl/certs
  • * TLSv1.3 (IN), TLS handshake, Server hello (2):
  • * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
  • * TLSv1.3 (IN), TLS handshake, Certificate (11):
  • * TLSv1.3 (IN), TLS handshake, CERT verify (15):
  • * TLSv1.3 (IN), TLS handshake, Finished (20):
  • * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
  • * TLSv1.3 (OUT), TLS handshake, Finished (20):
  • * SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
  • * ALPN: server accepted h2
  • * Server certificate:
  • *  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=github.com
  • *  start date: Feb 14 00:00:00 2023 GMT
  • *  expire date: Mar 14 23:59:59 2024 GMT
  • *  subjectAltName: host "github.com" matched cert's "github.com"
  • *  issuer: C=US; O=DigiCert Inc; CN=DigiCert TLS Hybrid ECC SHA384 2020 CA1
  • *  SSL certificate verify ok.
  • * using HTTP/2
  • * h2h3 [:method: GET]
  • * h2h3 [:path: /]
  • * h2h3 [:scheme: https]
  • * h2h3 [:authority: github.com:8443]
  • * h2h3 [user-agent: curl/7.88.1]
  • * h2h3 [accept: */*]
  • * Using Stream ID: 1 (easy handle 0xaaab010bd9e0)
  • > GET / HTTP/2
  • > Host: github.com:8443
  • > user-agent: curl/7.88.1
  • > accept: */*
  • >
  • * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
  • * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
  • * old SSL session ID is stale, removing
  • 复制代码

    进一步测试,发往 127.0.0.1:8443 的 https 请求,也正确地按照 ssl_preread 的结果,转发到了 github
  • 回复

    使用道具 举报

    50

    主题

    587

    回帖

    2170

    积分

    金牌会员

    积分
    2170
    发表于 2023-5-22 15:28:00 | 显示全部楼层
    本帖最后由 diocat 于 2023-5-22 15:58 编辑

    dvbhack 发表于 2023-5-22 15:50

    进一步测试,发往 127.0.0.1:8443 的 https 请求,也正确地按照 ssl_preread 的结果,转发到了 github ...

    "


    试试把这个配置删了
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|HS2V主机综合交流论坛

    GMT+8, 2024-5-21 00:14 , Processed in 0.121515 second(s), 3 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2023 Discuz! Team.

    快速回复 返回顶部 返回列表