nginx php fpm proxy,Nginx Proxy -> Varnish -> Nginx-> PHP -fpm 这个架构为什么无法访问?错误是 503,返回的是 Varnish 无法连接...

简单说:Nginx Proxy 监听 80 端口,将请求全部转发给 Varnish(8080 端口),Varnish 进行处理后,再将请求转发给 Nginx(8081 端口),接着遇到 php 文件就交给 PHP-fpm ( 9000 端口)。

问题应该是出在 Nginx Proxy 和 Varnish 以及 Nginx 之间。

注释:在 Varnish 前面再加一层 Nginx Proxy,是因为每天晚上都要进行网页 302 跳转,Nginx 控制跳转只需要 return 302 状态码和一个 URL 就好了,而 Varnish 不好控制页面跳转(因为把 PHP 请求都缓存了 10 分钟,PHP 请求在刚设置跳转时的 10 分钟内无法到达 PHP-fpm ),而又不想因为跳转而关掉 Varnish 导致后端压力过大。

Nginx Proxy 的配置:

upstream varnish {

server 127.0.0.1:8080 weight=5;

}

server {

listen 80;

server_name example.com

server_tokens off;

root /www/path/to/the/root/folder;

location / {

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $http_host;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_pass http://varnish;

}

}

Varnish 配置文件 default.vcl:

vcl 4.0;

backend default {

.host = "127.0.0.1";

.port = "8081";

}

Varnish 配置文件 varnish.params:

VARNISH_LISTEN_PORT=8080

Nginx 配置:

server {

listen 8081;

server_name example.com

server_tokens off;

root /www/path/to/the/root/folder;

location / {

index index.php index.html;

try_files $uri $uri/ =404;

}

location ~* \.php$ {

try_files $uri =404;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值