我很长时间以来一直在使用两个nginxs服务器解决问题,第一个作为反向代理,第二个作为后端服务器。
这是我的设计:
此设计适用于小型SQL请求,但是由于数据花了太多时间返回反向代理,反向代理与客户端之间的连接已关闭(我想),反向必须启动一个新的反向代理。一个人
当我从本地客户端向反向代理的本地HTTP地址发出请求时,它运行良好
这是我的Nginx配置
反向代理:
server {
listen 80 deferred;
server_name FQDN;
if ($request_method !~ ^(GET|HEAD|POST|PUT)$ )
{
return 405;
}
access_log /var/log/nginx/qa.access.log;
error_log /var/log/nginx/qa.error.log debug;
location /ws/ {
proxy_pass http://IP:8080/;
proxy_redirect default;
proxy_http_version 1.1;
proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 1200s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
send_timeout 1200s;
#proxy_connect_timeout 300s;
#proxy_send_timeout 300s;
add_header Front-End_Https on;
}
location / {
return 444;
}
}
后端服务器:
server {
listen 8080 deferred;
root /home/Websites/ws2.5/web;
index index.html index.htm index.nginx-debian.html index.php;
server_name NAME_BACKEND;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
#fastcgi_read_timeout 300;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/ws2.5_error.log debug;
access_log /var/log/nginx/ws2.5_access.log;
location ~ /\.ht {
deny all;
}
}
当它起作用时,这是我在日志中看到的内容:
BACKEND - [10/Aug/2020:17:40:22 +0200] "GET /me/patents/ HTTP/1.1" 200 25441300 "-" "RestSharp/105.2.3.0"
REVERSE PROXY - [10/Aug/2020:17:41:05 +0200] "GET /ws/me/patents/ HTTP/1.1" 200 25441067 "-" "RestSharp/105.2.3.0"
这是它不起作用时返回的内容:
BACKEND - [10/Aug/2020:16:28:39 +0200] "GET /me/patents/ HTTP/1.1" 200 25444257 "-" "RestSharp/105.2.3.0"
REVERSE PROXY - [10/Aug/2020:16:29:39 +0200] "GET /ws/me/patents/ HTTP/1.1" 200 142307 "-" "RestSharp/105.2.3.0"
在两种情况下,后端都会发送预期的数据,但是在第二种情况下,我们可以看到反向代理收到的数据少于BACKEND发送的数据