文档说明:只记录关键地方;
nginx端口复用例子
使用 $ssl_preread_protocol
$ssl_preread_server_name
$ssl_preread_alpn_protocols
三个变量的组合,来区分不同的服务
| |
| stream { |
| log_format main '$remote_addr [$time_local] ' |
| '$protocol $status $bytes_sent $bytes_received ' |
| '$session_time "$upstream_addr" ' |
| '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"'; |
| |
| access_log logs/access.log main; |
| resolver 223.5.5.5 223.6.6.6 ; |
| |
| map $ssl_preread_protocol $upstream_name { |
| "TLSv1.3" $name; |
| default https_default; |
| } |
| |
| |
| map "$ssl_preread_server_name$ssl_preread_alpn_protocols" $name { |
| default https_default; |
| |
| |
| ~http-proxy.xiaoshuogeng.com sync_chromium; |
| ~http-proxy.xiaoshuogeng.comh2,http/1.1 https; |
| |
| } |
| |
| |
| upstream https_default { |
| server 127.0.0.1:8444; |
| } |
| |
| upstream sync_chromium { |
| server 127.0.0.1:8443; |
| } |
| |
| upstream https { |
| server 127.0.0.1:8445; |
| } |
| |
| |
| server { |
| listen 443 reuseport; |
| proxy_pass $upstream_name; |
| ssl_preread on; |
| } |
| |
| include /etc/nginx/stream/*.conf; |
| } |
| |
| |
| |
http 服务 8445 端口 普通网页服务
| server { |
| listen 8445 ssl http2; |
| server_name http-proxy.xiaoshuogeng.com ; |
| |
| charset utf-8; |
| |
| ssl_certificate /tls/wildcard.xiaoshuogeng.com.fullchain.pem; |
| ssl_certificate_key /tls/wildcard.xiaoshuogeng.com.key.pem; |
| ssl_session_timeout 1d; |
| ssl_session_cache shared:MozSSL:10m; |
| ssl_session_tickets off; |
| |
| ssl_protocols TLSv1.3; |
| ssl_prefer_server_ciphers off; |
| |
| |
| add_header X-Frame-Options "SAMEORIGIN"; |
| add_header X-XSS-Protection "1; mode=block"; |
| add_header X-Content-Type-Options "nosniff"; |
| add_header Content-Security-Policy upgrade-insecure-requests; |
| add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; |
| add_header Referrer-Policy "no-referrer"; |
| |
| root /usr/share/nginx/html; |
| location / { |
| index index.html index.htm; |
| } |
| |
| } |
| |
| |
http 服务 8444 端口 (默认路由服务返回444)
| server { |
| listen 8444 ssl http2 default_server; |
| listen [::]:8444 ssl http2 default_server; |
| server_name _; |
| ssl_protocols TLSv1.2 TLSv1.3; |
| ssl_reject_handshake on; |
| return 444; |
| } |
| |
| |
| |
| server { |
| listen 80 default_server; |
| listen [::]:80 default_server; |
| server_name _; |
| return 444; |
| } |
| |
| server { |
| listen 80; |
| listen [::]:80; |
| server_name http-proxy.xiaoshuogeng.com; |
| rewrite ^(.*) https://$server_name$1 permanent; |
| } |
| |
参考文档
- ngx_stream_core_module
- Module ngx_stream_upstream_module
- Module ngx_stream_access_module
- ngx_http_proxy_module
- nginx 根据服务器名称选择上游 ngx_stream_ssl_preread_module
- nginx tcp-udp-load-balancer
- nginx http 通用配置
- nginx解决跨域关键点
- nginx 的http_proxy_connect_module模块使用
- Nginx与安全有关的几个配置
- Nginx的几个常用配置和技巧
- nginx features
- nginx documentation
- IP Transparency and Direct Server Return with NGINX
- iptables四表五链
- 四表五链
- 过渡到 nftables
实践例子
- 快速同步chromium源码以及拉取gcr.io容器镜像
- 快速下载chromium源码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术