想请问有没有类似的项目可以推荐一下的?想部署一个看看。
或者这类服务该用什么关键词搜?
感觉有点像虚拟浏览器了都。
]]>location / { root /home/party_game/dist; # 访问根目录 index index.html index.htm; # 入口文件 try_files $uri $uri/ /index.html; }
然后正常情况转发后端请求应在再写一个 location 拦截,也就是这样
location /api { proxy_pass http://localhost:60101; }
看着也没啥问题是吧?但是震惊我的是,我在前端项目和后端项目里配置的请求地址前缀都是 pgApi (例: http://localhost:60101/pgApi/auth/login ),如此我又尝试了把请求拦截换成了
location /abc { proxy_pass http://localhost:60101; } 或者 location /xxxx { proxy_pass http://localhost:60101; }
但是 nginx 都能把前端请求正常的转发到后端服务上,这个是为什么呀? 有点无法理解这部分原理,网上也没有搜到比较符合我问题的答案,特来请教
]]>访问 127.0.0.1/git/ 成功跳转到 8085 端口容器的 web 页面,但是发现有诸多问题:
类似这种二级目录的反向代理,是不是天然有缺陷,没办法像 二级域名 或 三级域名 反代那样完美实现?
注:
location /git/ { proxy_http_version 1.1; proxy_pass http://192.168.1.13:8085/; }
]]>一、rewrite 指令的正则表达式是部分匹配还是完全匹配才生效?
比如下面的配置中,请求 /name/jane-lotus 肯定会触发 rewrite 指令,最终请求地址为 http://user-center/users?name=jane-lotus 。
那么请求 /name/regions/bbb 会不会触发 rewrite 的 URI 替换?最终请求地址是多少?
这篇文章说不会触发 rewrite ,AI 的回答是会触发 rewrite 。
location /name/ { rewrite /name/([^/]+) /users?name=$1 break; proxy_passs http://user-center/main/basicinfo/; }
二、还是上面的配置,假如原始请求里带了查询参数,那么触发 rewrite 后会不会把原始请求参数也追加给新的请求地址? rewrite 新目标里有没有新的查询参数是否会影响老的查询参数追加到最终请求里?
三、是否有比较系统的 nginx 配置教程推荐或者模拟测试环境验证 nginx 详细执行过程的方法?
]]> location ~ "(?x)^/git(?<path>/.*/(?:HEAD ' info/refs ' objects/(?:info/[^/]+ ' [0-9a-f]{2}/[0-9a-f]{38} ' pack/pack-[0-9a-f]{40}\.(?:pack ' idx)) ' git-upload-pack))$" { error_page 491 = @auth; if ($query_string = service=git-receive-pack) { return 491; } client_max_body_size 0; fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; include fastcgi_params; fastcgi_param GIT_HTTP_EXPORT_ALL ""; fastcgi_param GIT_PROJECT_ROOT /srv/git; fastcgi_param PATH_INFO $path; fastcgi_param REMOTE_USER $remote_user; fastcgi_pass unix:/var/run/fcgiwrap.socket; } location ~ "^/git(?<path>/.*/git-receive-pack)$" { error_page 491 = @auth; return 491; } location @auth { auth_basic "Git write access"; auth_basic_user_file /srv/git/.htpasswd; client_max_body_size 0; fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; include fastcgi_params; fastcgi_param GIT_HTTP_EXPORT_ALL ""; fastcgi_param GIT_PROJECT_ROOT /srv/git; fastcgi_param PATH_INFO $path; fastcgi_param REMOTE_USER $remote_user; fastcgi_pass unix:/var/run/fcgiwrap.socket; } location ~ ^/git(?<path>/.*)$ { alias /usr/share/cgit; try_files $1 @cgit; } location @cgit { include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi; fastcgi_param PATH_INFO $path; fastcgi_param QUERY_STRING $args; fastcgi_param HTTP_HOST $server_name; fastcgi_param CGIT_CONFIG /srv/git/.cgitrc; fastcgi_pass unix:/var/run/fcgiwrap.socket; }
]]>我们的主要需求是反向代理,现在用 nginx 在跑。因为日常运维的同事对命令行不太熟,操作也麻烦,想通过 gui 工具来进行管理,因为之前遇到过好几次命令行操作失败不小心改错了。
现在主要担心的是第一个 npm 好像内置了 openresty ,似乎单独升级都不是太方便。第二这个东西毕竟套了一层 docker 容器,不知道稳定性如何,万一崩了不像普通 nginx 那么容易恢复。
或者有其他类似的工具可以推荐不?主要需求其实就是通过 gui 界面,能减少日常配置的工作复杂度和出错几率。
谢谢!
]]>昨天, 在宝塔上对线上服务 A 修改 proxy_pass, 端口从 7511 改成 7501:
location / { proxy_pass http://localhost:7501; }
更新配置后, 错误日志显示 upstream 依旧是 127.0.0.1:7511, 询问 AI, 反复折腾后, 依旧没能解决. 但在此期间, 没有任何报错, 包括在宝塔上保存配置, 在服务器上 nginx -t, nginx -s reload, nginx -T 等.
推测配置被缓存了, 但为什么被缓存, 不清楚. 只能先重启 nginx 把服务搞上线.
重启之前就隐隐觉得这次重启肯定不顺利, 毕竟 nginx -s reload 没有生效, 有些地方肯定有问题. 果然报错: 7503 端口被占用, nginx 无法启动.
我瞬间就慌了, 在做了两次无效重复后, 理智回来了: nginx -T 查出 7503 在服务 B 的配置文件, 果断注释那一行然后成功启动 nginx, 线上服务恢复, 服务 A 也正常了.
7503 端口本身就被一个 next.js 项目占用, 但不知道为什么还要写到 nginx 配置文件, 只能认为不会 nginx. 问了前端负责人, 到现在也没回我~~
nginx version: nginx/1.20.2
]]>http2
可以正常获取到客户端 IP ,通过 h3quic
连接则无法获取到真实的客户端 IP ,只能获取到 127.0.0.1 。 请问各位大佬,在保持使用四层反代的前提下,如何配置可以通过quic
获取到客户端 IP 。
REMOTE_ADDR: 127.0.0.1 HTTP_CLIENT_IP: 未设置 HTTP_X_FORWARDED_FOR: 未设置 HTTP_X_REAL_IP: 未设置 HTTP_FORWARDED: 未设置 HTTP_FORWARDED_FOR: 未设置 HTTP_X_FORWARDED: 未设置
map $ssl_preread_server_name $name { default default_backend; } upstream default_backend { server 127.0.0.1:6443; # 站点 } server { listen 443 reuseport; listen 443 udp reuseport; proxy_pass $name; ssl_preread on; proxy_protocol on; }
server { listen 80; listen 6443 ssl proxy_protocol ; listen 6443 quic reuseport; http2 on; server_name abc.com www.abc.com; index index.php index.html; root /wwwroot/abc.com; set_real_ip_from 127.0.0.1; real_ip_header proxy_protocol; ... }
]]>现在我有一个笔记本,里面有个虚拟机,虚拟机里面部署了我的 sphinx 文档.
然后在外面笔记本 windows 系统上面启动 nginx,反代虚拟机的 sphinx 文档站点.
然后我笔记本开机会自动启动虚拟机,nginx.
现在问题来了,我笔记本重启,虚拟机也重启好了,
我在台式机上访问 nginx 的反代的 sphinx 文档站点,提示 502?一定要我去把 nginx 再重启一下,502 才消, 这种问题怎么解决?
还有一个问题,我笔记本重启后,有时候一段时间后会陷入黑屏状态,但是我明明设置了电源状态为不黑屏啊? 这种问题又如何解?
]]> location /xai { proxy_pass https://api.x.ai/; proxy_ssl_server_name on; proxy_set_header Host api.x.ai; proxy_set_header Connection ''; proxy_http_version 1.1; chunked_transfer_encoding off; proxy_buffering off; proxy_cache off; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; }
请求:
https://chat.xxxxx.com/xai/v1/chat/completions
报错:
{ "code": "Some requested entity was not found", "error": "No handler found on route. Please double check your URL and consult https://api.x.ai/docs for more information." }
]]>我现在在用 Nginx
代理一个 Fastapi
应用,从局域网内其他机器通过wrk
直接压测后端应用的一个简单返回,在 8 核 CPU 上有 4w QPS ,但通过 Nginx 代理 Fastapi 后,QPS 只有离谱的 2-3k ,我看后端机器 CPU 是没有跑满的,Nginx CPU 反而是占用满了。
压测结果:
2 threads and 200 connections Thread Stats Avg Stdev Max +/- Stdev Latency 115.25ms 86.47ms 712.60ms 45.32% Req/Sec 0.91k 1.01k 3.74k 87.67% 27096 requests in 15.02s, 9.25MB read Requests/sec: 1804.16 Transfer/sec: 630.75KB
上面操作均在 3 台局域网内机器,实际上在 Nginx 机器通过 curl 访问后端也只是 2ms 的延迟,请求这问题是出在哪儿了呢? Nginx 使用的是默认配置,没经过优化。
另外,通过 docker 部署 traefik 反向代理后压测,后端能正常跑满 CPU ,延迟也是正常的几毫秒之内,就是 traefik CPU 占用也挺大的,按道理来说 Nginx 性能应该强于 traefik 吧?
这个问题困扰了我好几天了,问 GPT Nginx 优化相关的也只是反复回答链接数、keep alive 这些,都试过了没作用,请问各位大哥 Nginx 应该怎么配置优化呢?
]]>loc: /aa ==> http://127.0.0.1:28080/aa
pro: /aa ==> http://127.0.0.1:8011/api/
其它: /aa ==> http://127.0.0.1:8022/api/
大佬们,原来只有 loc 和其它一切正常,加上 pro 就不行了,如何配置可以实现这个效果吗?似乎 if 里面 proxy_pass 不能有/api/地址
location /aa { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; if ($http_environment_name = "loc" ) { proxy_pass http://127.0.0.1:28080; break; } if ($http_environment_name = "pro" ) { proxy_pass http://127.0.0.1:8011/api/; break; } proxy_pass http://127.0.0.1:8022/api/; }
]]>nginx-proxy-manager 相比于 nginx-proxy 有什么优势吗? nginx-proxy-manager 能自动帮其他 docker 反代端口吗?
]]>server { listen 10086 ssl; server_name abc.com; location / { proxy_pass http://192.168.0.100:10086; 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-Proto $scheme; } location /book { proxy_pass http://192.168.0.100:10010; 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-Proto $scheme; } }
类似这样配置了 nginx 之后 直接访问 abc.com:10086 端口访问全部没问题 但是转发的第二个端口
abc.com:10086/book
并不能成功转发到 192.168.0.100:10010 浏览器调试发现使用 abc.com:10086/book 发出的请求中 css js 之类的都是
abc.com:10086/static/?.css abc.com:10086/static/?.js
而并没有到
abc.com:10086/book/static/?.css abc.com:10086/book/static/?.js
状态都是 404 了 问了一下 gpt 说是需要找到真实的静态资源地址,这个容器的话怎么搞呢?还是说我的 nginx 需要配置其他配置项才可以呢,求大佬们帮助
]]>但我的配置文件没有按照预期那样工作, 直接访问域名根路径的时候还是反代到了 registry-1.docker.io 导致返回 404, 希望有熟悉 nginx 的老哥帮忙看看, 这要怎么修改?
我的 server 配置如下
location = / { add_header Cache-Control private; alias /var/www/html/; index index.html; } location / { # Docker hub 的官方镜像仓库 proxy_pass https://registry-1.docker.io; proxy_set_header Host registry-1.docker.io; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; # 关闭缓存 proxy_buffering off; # 转发认证相关 proxy_set_header Authorization $http_authorization; proxy_pass_header Authorization; # 对 upstream 状态码检查,实现 error_page 错误重定向 proxy_intercept_errors on; recursive_error_pages on; # 根据状态码执行对应操作,以下为 381 、302 、387 状态码都会触发 error_page 301 302 307 = @handle_redirect; }
]]>/aisp/approval/
路径的请求转发给我,我收到请求后根据user-agent
判断是移动端还是 pc 端请求,如果为移动端的,则去当前服务器的/home/centos/web/h5
目录下响应对应的静态文件。如果是/aisp/approval/api/
路径下的请求则请求后端服务,当前的配置: server { listen 9999; server_name localhost; location /aisp/approval/ { if ($is_mobile = 0) { rewrite ^/aisp/approval/(.*)$ https://b.com/$1 permanent; } alias /home/centos/web/h5/; try_files $uri $uri/ /index.html; } location /aisp/approval/api/ { limit_conn perip 1000; proxy_pass http://10.156.166.23:9088/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; client_max_body_size 600M; client_body_buffer_size 512k; } }
现在的问题是通过移动端请求a.com/aisp/approval/workOrder/orderHandlerDetails
,error.log 会报:
open() "/usr/local/nginx/html/home/centos/supervision/web/h5/index.html" failed (2: No such file or directory)
/usr/local/nginx/html 是我 nginx 的安装目录,我要如何配置才能在请求 a.com/aisp/approval/workOrder/时响应/home/centos/supervision/web/h5/目录下的 index.html
]]>使用 NetHogs 查看流量发现 unknown TCP 的 RECEIVED 一直居高不下,停掉 docker 内的 nginx 就正常了,目前只放了一个空的页面这个流量也很高。
请大佬支支招,如何排查呢。系统是 debian12 ,程序都安装在 docker 内
]]>我想实现在一台 Linux 虚拟机上配置 nginx ,用于代理家里这三台虚拟机上的服务,可以实现 https 访问
http://localhost:30
但是转发过去就变成了
http://localhost/abc/
请问这个有什么解决办法嘛?
]]>~/info 限流失败
~info 和~/info 都能匹配到值,$limit_key_pc_page_info 的值输出 page_info
为什么加/符号会影响限流?$limit_key_pc_page_info 里面有值
# 变量-URI map $uri $limit_key_pc_page_info { ~/info "page_info"; #~info "page_info"; default ""; } limit_req_zone $limit_key_pc_page_info zOne=limit_zone_pc_page_info:10m rate=1r/s; server { listen 80; server_name www.dunhanson.com; charset utf-8; location / { # 限流 limit_req zOne=limit_zone_pc_page_info nodelay; proxy_pass http://www_dunhanson_com; } } server { listen 80; server_name test.dunhanson.com; charset utf-8; location / { default_type text/plain; return 200 "$uri $limit_key_pc_page_info"; } }
curl http://test.dunhanson.com/info-558860051.html
输出: /info-558860051.html page_info
]]>如果在 nginx 配置中增加下边几项就报上边的错误。
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-Proto $scheme;
如果去除这几项就正常了。
所以想请问下,这种情况是怎么造成的。不理解。
]]> # 不加这一条就无法反向代理 favicon 日志 404 location = /favicon.ico { log_not_found off; proxy_pass http://official; } location / { proxy_pass http://official; proxy_set_header Host $host; }
我内部的 official 的 nignx 直接用端口访问, 是能看到 favicon 的.
试了好久才发现, 外部必须再写一条, 才能看到 favicon, 但是我不写 css 什么的, css 直接就没问题, 只有 favicon 有这个问题.
问过 AI 了, 老是照着结果回答.
为什么啊? 谢谢各位了.
]]>我将 centos 7 中的 nginx v1.20.1 配置迁移到了 rocky linux 9 中的 nginx v1.26.2 中,
使用的均为 rpm 包
nginx v1.20.1 是官方源中下载
nginx v1.26.2 是从 nginx 源中下载
迁移之后 headscale 被反向代理后的 8082 端口就无法访问了,但是原生的 8080 端口可以访问,
两个站点配置完全一样,是直接复制过去的
新版本的 nginx 日志中没有相关访问日志
并且 nginx 的主要更新日志,并没有什么头绪,所以发帖请教一下各位
以下是日志与配置
站点主要配置如下
server { listen 8082 ssl ; listen [::]:8082 ssl ; server_name xxxx; root /opt/headscale/headscale-ui/web; # SSL ssl_certificate /etc/nginx/cert/xxxx.crt; ssl_certificate_key /etc/nginx/cert/xxxx.key; ssl_protocols TLSv1.2 TLSv1.3; # logging # 这里其实有日志配置,但是不知道放进来就不能发帖 location /web { alias /opt/headscale/headscale-ui/web; index index.html; } # reverse proxy location / { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $server_name; proxy_redirect http:// https://; proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always; } }
headscale 的部分日志如下
Nov 01 17:13:17 xxxxxx tailscaled[2145341]: control: LoginInteractive -> regen=true Nov 01 17:13:17 xxxxxx tailscaled[2145341]: control: doLogin(regen=true, hasUrl=false) Nov 01 17:13:17 xxxxxx tailscaled[2145341]: Received error: fetch control key: Get "https://xxxxxx:8082/key?v=106": read tcp 192.168.2.199:36346->xx.xx.xx.xx:8082: read: connection reset by peer Nov 01 17:13:17 xxxxxx tailscaled[2145341]: health(warnable=login-state): error: You are logged out. The last login error was: fetch control key: Get "https://xxxxxx:8082/key?v=106": read tcp 192.168.2.199:36346->xx.xx.xx.xx:8082: read: connection reset by peer
nginx 的版本信息如下
旧服务器
nginx version: nginx/1.20.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.1.1k FIPS 25 Mar 2021 TLS SNI support enabled
新服务器
nginx version: nginx/1.26.2 built by gcc 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC) built with OpenSSL 3.0.7 1 Nov 2022 TLS SNI support enabled
]]>详细的编译参数放不进去,如果有需要的话,后续考虑截图放在后面
这段配置可以正常运行
location ~* /_next/static/.*(js|css|png|jpg|jpeg|svg|gif|ico|ttf|webp)$ { rewrite /_next/(.*) /.next/$1 break; try_files $uri $uri/; expires 1y; # 设置缓存时间为 1 年 add_header Cache-Control "public"; }
这段配置却找不到文件、响应体还会变成 308 重定向
location ~* /_next/static/.*(js|css|png|jpg|jpeg|svg|gif|ico|ttf|webp)$ { alias /app/.next/static/; # 将请求路径 /_next/static/ 映射到文件系统的 /app/.next/static/ expires 1y; # 设置缓存时间为 1 年 add_header Cache-Control "public"; }
]]>使用 nginx 反代堡垒机的 443 端口,登录堡垒机,运维 rdp 资产都没问题。 但运维 ssh 资产时,显示权限不对,登录失败。
两种资产都是用密码登录的,url 在反代前和反代后,感觉也没有区别。
]]>返回的 403 还是 nginx 自带的 403 页面
error_page 403 /403.html; location = /403.html { root D:/program/nginx/nginx-1.18.0/html; } if ($http_user_agent ~ "Baiduspider") { return 403; }
]]>502
,无法正常访问 我看了下error.log
说的是代理服务器和源站 ssl 握手失败 但是我在代理服务器里面写的是https
,而且代理服务器curl
能正常获取到内容 这个是源站的caddyfile
direct.example.com { reverse_proxy unix//var/discourse/shared/standalone/nginx.http.sock { header_up Host {host} header_up X-Real-IP {remote} header_up X-Forwarded-For {remote} header_up X-Forwarded-Proto {scheme} } header { Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" } } synapse.know-cnu.wiki { reverse_proxy localhost:8008 { # WebSocket 连接的默认配置 header_up Host {host} header_up X-Real-IP {remote} header_up X-Forwarded-For {remote} header_up X-Forwarded-Proto {scheme} # 处理 WebSocket 连接 transport http { read_buffer 0 } } # 设置 HSTS 头部 header { Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" }
这个是代理服务器的nginx.conf
,未使用ssl
server { listen 80; server_name example.com; location / { proxy_pass https://direct.example.com; 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-Proto $scheme; } }
error.log
如下
root@VM80459:~# tail -f /var/log/nginx/error.log 2024/08/24 06:08:57 [emerg] 3325#3325: "server" directive is not allowed here in /etc/nginx/nginx.conf:11 2024/08/24 06:09:05 [emerg] 3326#3326: "server" directive is not allowed here in /etc/nginx/nginx.conf:11 2024/08/24 06:10:18 [notice] 3373#3373: signal process started 2024/08/24 06:19:53 [notice] 3445#3445: signal process started 2024/08/24 06:20:02 [error] 3446#3446: *12 SSL_do_handshake() failed (SSL: error:0A000438:SSL routines::tlsv1 alert internal error:SSL alert number 80) while SSL handshaking to upstream, client: 1xx.1x.5x.xx, server: know-cnu.wiki, request: "GET / HTTP/1.1", upstream: "https://[2400:61xx:0:dx::xa:a0x]:443/", host: "example.com" 2024/08/24 06:20:02 [error] 3446#3446: *12 SSL_do_handshake() failed (SSL: error:0A000438:SSL routines::tlsv1 alert internal error:SSL alert number 80) while SSL handshaking to upstream, client: 10x.13x.5x.18x, server: example.com, request: "GET / HTTP/1.1", upstream: "https://15x.8x.2xx.xx:443/", host: "example.com"
]]>worker_processes auto; # 自动设置为 CPU 核心数 worker_rlimit_nofile 100000; # 增加每个 worker 进程可以打开的文件数 events { worker_connections 4096; # 增加每个 worker 进程的最大连接数 multi_accept on; # 允许每个 worker 进程同时接受多个连接 } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; server { listen 80; server_name es.x.com.cn; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name es.x.com.cn; # SSL 证书和密钥配置 ssl_certificate /usr/share/nginx/html/ssl-qianduan/es.x.com.cn_bundle.pem; ssl_certificate_key /usr/share/nginx/html/ssl-qianduan/es.x.com.cn.key; # SSL 优化配置 ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256'; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; ssl_stapling on; ssl_stapling_verify on; location / { root /usr/share/nginx/html; # 路径改成自己的 dist 路径 index index.html index.htm; try_files $uri $uri/ /index.html; #解决刷新页面变成 404 问题的代码 } location /prod-api/ { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.16.238.13:8089/; } } server { listen 80; server_name esb.x.com.cn; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name esb.x.com.cn; # SSL 证书和密钥配置 ssl_certificate /usr/share/nginx/html/ssl-houduan/esb.x.com.cn_bundle.pem; ssl_certificate_key /usr/share/nginx/html/ssl-houduan/esb.x.com.cn.key; location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://172.16.238.13:8089/; } } # 阻止通过 IP 地址或未知的域名访问 server { listen 80 default_server; listen 443 default_server ssl; # SSL 证书和密钥配置 ssl_certificate /usr/share/nginx/html/ssl-houduan/esb.x.com.cn_bundle.pem; ssl_certificate_key /usr/share/nginx/html/ssl-houduan/esb.x.com.cn.key; server_name es.x.com.cn; return 444; # 返回一个非标准的状态码,通常用于阻止客户端的访问 } }
]]>Aug 15 13:07:32 hostname nginx[3297853]: nginx: [emerg] host not found in upstream "backend.example.com" in /etc/nginx/sites-enabled/app1:25 Aug 15 13:07:32 hostname nginx[3297853]: nginx: configuration file /etc/nginx/nginx.conf test failed Aug 15 13:07:32 hostname systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE Aug 15 13:07:32 hostname systemd[1]: nginx.service: Failed with result 'exit-code'. Aug 15 13:07:32 hostname systemd[1]: Failed to start A high performance web server and a reverse proxy server.
在这几秒前崩了没写日志,这个日志是刚自动重启后又崩了的。没改配置,10 秒后第三次自动重启就成功了。backend 在别的服务器上,内网 DNS 也一直正常
]]>172.68.244.177 - - [04/Aug/2024:04:04:10 -0400] "GET /find-app/%E0%B8%AD%E0%B8%B2%E0%B8%8A%E0%B8%B5%E0%B8%9E%E0%B8%82%E0%B8%AD%E0%B8%87%E0%B8%8A%E0%B8%B2%E0%B8%A7%E0%B8%AB%E0%B8%A7%E0%B8%B9%E0%B9%88%E0%B8%AB%E0%B8%A5%E0%B8%B4%E0%B8%87%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%81%E0%B8%9B%E0%B8%A5%E0%B8%B2%E3%80%90ta777.me%E3%80%91%E0%B8%AD%E0%B8%B2%E0%B8%8A%E0%B8%B5%E0%B8%9E%E0%B8%82%E0%B8%AD%E0%B8%87%E0%B8%8A%E0%B8%B2%E0%B8%A7%E0%B8%AB%E0%B8%A7%E0%B8%B9%E0%B9%88%E0%B8%AB%E0%B8%A5%E0%B8%B4%E0%B8%87%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%81%E0%B8%9B%E0%B8%A5%E0%B8%B2%E3%80%90ta777.me%E3%80%91w7t?page=2 HTTP/1.1" 403 571 "-" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/116.0.1938.76 Safari/537.36" 52.167.144.211 172.71.222.36 - - [04/Aug/2024:04:04:10 -0400] "GET /find-app/%E6%B9%96%E5%8D%97%E6%B0%B4%E5%88%A9%E6%B0%B4%E7%94%B5%E8%81%8C%E4%B8%9A%E6%8A%80%E6%9C%AF%E5%AD%A6%E9%99%A2%E6%AF%95%E4%B8%9A%E8%AF%81%E6%A0%B7%E6%9C%AC%E5%9B%BE%E7%89%87%E2%8F%A9%E5%8A%9E%E7%90%86%E7%BD%91zhengjian.shop%E2%8F%AA-%E5%93%AA%E9%87%8C%E4%B9%B0%E6%B9%96%E5%8D%97%E6%B0%B4%E5%88%A9%E6%B0%B4%E7%94%B5%E8%81%8C%E4%B8%9A%E6%8A%80%E6%9C%AF%E5%AD%A6%E9%99%A2%E6%AF%95%E4%B8%9A%E8%AF%81%E6%A0%B7%E6%9C%AC%E5%9B%BE%E7%89%87%F0%9F%8C%9F%E5%8A%9E%E8%AF%81%E7%BD%91zhengjian.shop%F0%9F%8C%9F-%E5%BC%A0%E5%AE%B6%E6%B8%AF%E6%B9%96%E5%8D%97%E6%B0%B4%E5%88%A9%E6%B0%B4%E7%94%B5%E8%81%8C%E4%B8%9A%E6%8A%80%E6%9C%AF%E5%AD%A6%E9%99%A2%E6%AF%95%E4%B8%9A%E8%AF%81%E6%A0%B7%E6%9C%AC%E5%9B%BE%E7%89%87%E5%93%AA%E9%87%8C%E6%9C%89-%E5%93%AA%E9%87%8C%E5%8A%9E%E6%B9%96%E5%8D%97%E6%B0%B4%E5%88%A9%E6%B0%B4%E7%94%B5%E8%81%8C%E4%B8%9A%E6%8A%80%E6%9C%AF%E5%AD%A6%E9%99%A2%E6%AF%95%E4%B8%9A%E8%AF%81%E6%A0%B7%E6%9C%AC%E5%9B%BE%E7%89%87Q5?page=3 HTTP/1.1" 403 571 "-" "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm) Chrome/116.0.1938.76 Safari/537.36" 52.167.144.211
以下是完整配置
server { listen 80; listen 443 ssl; # ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem; ## ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS; ## enable HSTS including subdomains add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; server_name domain.com www.domain.com; index index.html index.htm index.php; root /opt/htdocs/www.domain.com/public; #301 if ($host = 'domain.com') { rewrite ^/(.*)$ https://www.domain.com/$1 permanent; } #location ~ /find-app { if ($http_user_agent ~* "bingbot|AhrefsBot") { return 403; } #} location / { try_files $uri $uri/ /index.php?$query_string; } #申请 let’s Encrypt SSL 用 location ~ /.well-known { allow all; } if (!-e $request_filename) { } location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 15d; } access_log /data0/logs/domain.log access; }
]]>操作:使用 Nginx 反代了三个网站
网站一为:map.~.com → 81 端口,开启 https
网站二为:frp.~.com → 7800 端口,未开启 https
网站三为:r730test.~.com → 81 端口,未开启 https
其中 81 端口为 frps 的 http 端口,map.~.com 和 r730test.~.com 都是部署在内网,用 frp 穿透出来的,7800 是 frp 的监控面板端口
问题:现在访问 map.~.com 是正常的,但是访问 frp.~.com 和 r730test.~.com 会被跳转到 https://frp.~.com/和 https://r730test.~.com/ ,而且显示的是 map.~.com 的内容
在添加 map.~.com 的反代之前都是正常的,添加了 map.~.com 的反代之后就出问题了
Nginx 配置文件如下
https://pastecode.io/s/uni4h5f6
]]>