分类 Nginx 下的文章

Nginx转发两个后端服务,请求返回502,没有进入到后端服务,排查Nginx日志发现:

no live upstreams while connecting to upstream

造成该问题的原因:

转发到upstream两个节点的请求都出现了超时(upstream timed out (110: Connection timed out) while reading response header from upstream),Nginx认为upstream中的两个节点都挂掉了,无法使用,所以拒绝新请求的连接,返回502。

需要等待fail_timeout时间后,才能继续尝试转发,这是属于Nginx的被动健康检查机制。

- 阅读剩余部分 -

变量值来源是否显示端口说明
$host按照 请求行中的Host > 请求头中的Host > server_name 的值 优先级获取"Host:port"显示值为a:b的时候,只显示a
$http_host请求头中的Host"Host:port",port存在就显示,请求头中Host是多少 $http_host就是多少
$proxy_hostproxy_pass 指定的地址是(默认80不显示)"Host:port" proxy_pass指定的 "Host:port",当port为80的时候只有“Host”,其它端口,正常显示为 “Host:port”

- 阅读剩余部分 -

promtail通过nginx向loki发送数据,收到以下报错

level=error ts=2025-05-08T01:21:05.955472787Z caller=client.go:380 component=client host=local-loki:3100 msg="final error sending batch" status=413 error="server returned HTTP status 413 Request Entity Too Large (413): <html>"

排查nginx日志,发现

2025/05/08 09:21:06 [error] 21#21: *62769236 client intended to send too large body: 1312028 bytes, client: 10.40.30.155, server: , request: "POST /loki/api/v1/push HTTP/1.1", host: "local-loki:3100"
 - | 10.40.30.155 | - | 08/May/2025:09:21:06 +0800 | POST /loki/api/v1/push HTTP/1.1 | 413 | 183 | - | promtail/2.6.1 | - | 0.032 | - | - | - | local-loki:3100

触发了Nginx的最大请求体限制,收到了 413 (Request Entity Too Large) error

- 阅读剩余部分 -

官方文档: 从源代码构建Nginx

基于源码,定制编译Nginx,提供了关于源码编译Nginx的示例

  1. 不使用外部模块编译Nginx
  2. 使用外部模块编译Nginx

编译环境

Nginx版本: 1.27.5

操作系统: Ubuntu 18.04

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic

- 阅读剩余部分 -

计划

1.php服务相关文件。

2.后端使用php-fpm容器启动

3.前端使用本地nginx代理,或者使用容器nginx代理(可不映射php-fpm端口)

php项目目录

/var/www/example/

Index.php文件在该目录

示例

1.使用本地nginx+容器php-fpm服务部署

2.使用容器nginx+容器php-fpm服务部署

- 阅读剩余部分 -