Today, a 502 Bad Gateway exception occurred on an interface of an operating system of the company.
Ideas to solve the problem: Go to the server to view the nginx exception log and find the nginx exception log analysis problem
1. Use sudo nginx -t to view the nginx configuration file location
ais-di@parrot:/etc/nginx$ sudo nginx -t
[sudo] password for ais-di:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
2. Check the nginx.conf configuration file to find the location of its exception log::
ais-di@parrot:/etc/nginx$ cat /etc/nginx/nginx.conf | grep error.log
error_log /var/log/nginx/error.log;
3. Check the exception log file to find the request of your own host
ais-di@parrot:/etc/nginx$ sudo cat /var/log/nginx/error.log | grep 10.25.8.103
2022/04/19 10:32:24 [error] 893#893: *7554500 connect() failed (111: Connection refused) while connecting to upstream, client: 10.25.8.103, server: marsops.i-tetris.com, request: "GET /api/nlu/sp/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_esp_function_on_20220417 HTTP/1.1", upstream: "http://10.86.11.38:8877/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_esp_function_on_20220417", host: "ais.i-tetris.com:9890", referrer: "http://ais.i-tetris.com:9890/"
2022/04/19 10:32:27 [error] 893#893: *7554507 connect() failed (111: Connection refused) while connecting to upstream, client: 10.25.8.103, server: marsops.i-tetris.com, request: "GET /api/nlu/sp/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_esp_function_on_20220417 HTTP/1.1", upstream: "http://10.86.11.38:8877/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_esp_function_on_20220417", host: "ais.i-tetris.com:9890", referrer: "http://ais.i-tetris.com:9890/"
2022/04/19 10:43:33 [error] 893#893: *7554621 connect() failed (111: Connection refused) while connecting to upstream, client: 10.25.8.103, server: marsops.i-tetris.com, request: "GET /api/nlu/sp/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_auto_emergency_braking_on_20220417 HTTP/1.1", upstream: "http://10.86.11.38:8877/wa/single_pre_annotation?table=expr_model_inbox&setName=Abasic_kaidi_jiaqi_auto_emergency_braking_on_20220417", host: "ais.i-tetris.com:9890", referrer: "http://ais.i-tetris.com:9890/"
4. Check the configuration file to see if the service starts normally.
When checking the nginx.conf file, the server block is not found because it is included in other configuration files. nginx supports multi-file configuration to find the corresponding file. View the port requested by the service
server {
listen 9890;
root /var/www/html/nlu;
index index.php index.html index.htm index.nginx-debian.html;
server_name marsops.i-tetris.com;
client_max_body_size 100M;
location / {
try_files $uri $uri/ =404;
}
location /api/nlu/review/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_pass http://127.0.0.1:20731/;
}
location /api/nlu/sp/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_pass http://10.86.11.38:8877/;
}
}
The requested interface prefix is "/api/nlu/sp/". It is found that the essence is to request the 10.86.11.38:8877 service. When logging in to the server, it is found that the service has not been started. Solve the problem on startup