我正在尝试镜像到达我们其中一项服务的请求,nginx 充当 Web 服务器。我已使用镜像指令将请求代理到 AWS ALB,但似乎 nginx 并未将请求复制到 ALB。
server {
listen 80;
server_name service-01.example;
root /srv/www/apps/service-01/public;
location / {
mirror /mirror;
try_files $uri @app;
}
location @app {
uwsgi_pass unix:/run/uwsgi-apps/service-01.sock;
uwsgi_read_timeout 300s;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_modifier1 5;}
location /mirror {
internal;
proxy_pass http://aws-alb$request_uri;
}
答案1
proxy_pass
位置块中的指令不应/mirror
包含$request_uri
,默认情况下会保留镜像请求的 URI。
我修改了你的配置如下:
server {
listen 80;
server_name service-01.example;
root /srv/www/apps/service-01/public;
location / {
mirror /mirror;
try_files $uri @app;
}
location @app {
uwsgi_pass unix:/run/uwsgi-apps/service-01.sock;
uwsgi_read_timeout 300s;
include uwsgi_params;
uwsgi_param UWSGI_SCHEME $scheme;
uwsgi_modifier1 5;
}
location /mirror {
internal;
proxy_pass http://aws-alb; # Remove the $request_uri variable
}
}