在使用nginx(版本是1.24.0)转发时,出现了api接口一会正常返回,一会返回 404.html的情况。
以下是我的nginx配置:
nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include conf.include/gateway-upstream.conf; include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8080; server_name localhost; #charset koi8-r; access_log logs/host.access.log main; error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } include conf.include/gateway_location.conf; } }
gateway-upstream.conf如下:
upstream gateway-upstream {
server 192.168.138.2:10006;
}
gateway-location.conf如下:
location /core/ {
proxy_pass http://gateway-upstream/;
}
在使用postman测试接口时,就出现了上述的问题。
排查了很久也没有发现问题。在网上看到说有可能时之前的nginx进程没有停掉导致的。由于我之前一直在测试nginx。频繁的reload。不知道是不是这些原因。所以我最后将nginx停止后重新启动。然后居然正常了,居然正常了,居然正常了,懵了。
希望有人知道原因的告诉一声,拜谢。