ฉันมีคอนเทนเนอร์ nginx ใน AWS ที่ทำพร็อกซีย้อนกลับสำหรับเว็บไซต์ของฉันเช่น https://example.com ฉันมีบริการแบ็กเอนด์ที่ลงทะเบียนใน DNS ภายในเครื่องโดยอัตโนมัติ - aws.local (ซึ่งทำโดย AWS ECS Auto-Discovery) ปัญหาที่ฉันมีคือ nginx จะแก้ไขชื่อเป็น IP เท่านั้นในระหว่างการเริ่มต้น ดังนั้นเมื่อคอนเทนเนอร์บริการถูกรีบูตและรับ IP ใหม่ nginx ยังคงลองใช้ IP เก่าและฉันมีข้อผิดพลาด "502 Bad Gateway"
นี่คือรหัสที่ฉันใช้:
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
include /etc/nginx/mime.types;
log_format graylog2_json '{ "timestamp": "$time_iso8601", '
'"remote_addr": "$remote_addr", '
'"body_bytes_sent": $body_bytes_sent, '
'"request_time": $request_time, '
'"response_status": $status, '
'"request": "$request", '
'"request_method": "$request_method", '
'"host": "$host",'
'"upstream_cache_status": "$upstream_cache_status",'
'"upstream_addr": "$upstream_addr",'
'"http_x_forwarded_for": "$http_x_forwarded_for",'
'"http_referrer": "$http_referer", '
'"http_user_agent": "$http_user_agent" }';
upstream service1 {
server service1.aws.local:8070;
}
upstream service2 {
server service2.aws.local:8080;
}
resolver 10.0.0.2 valid=10s;
server {
listen 443 http2 ssl;
server_name example.com;
location /main {
proxy_pass http://service1;
}
location /auth {
proxy_pass http://service2;
}
ฉันพบคำแนะนำในการเปลี่ยนการกำหนดค่า nginx เพื่อแก้ไขชื่อต่อคำขอ แต่จากนั้นฉันเห็นว่าเบราว์เซอร์ของฉันพยายามเปิด "service2.aws.local:8070" และล้มเหลวเนื่องจากชื่อ DNS ภายในของ AWS ฉันควรเห็น https://example.com/auth" บนเบราว์เซอร์ของฉัน
server {
set $main service1.aws.local:2000;
set $auth service2.aws.local:8070;
location /main {
proxy_http_version 1.1;
proxy_pass http://$main;
}
location /auth {
proxy_http_version 1.1;
proxy_pass http://$auth;
}
คุณช่วยฉันแก้ไขมันได้ไหม? ขอบคุณ !!!