Q&A
事象
nginxで、/healthzに来た通信を別のドキュメントルートに行くようにしたいのですが、うまくいきません。
404が返ってきてしまいます。
$ curl http://localhost/healthz/index.html % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<html> <head><title>404 Not Found</title></head> (以下略)
- ログには
[error] 32#32: *1 open() "/etc/nginx/html/healthz/index.html" failed (2: No such file or directory)
と出ます。 - 設定ファイルは以下の通りで、
/healthz
のrootに/usr/share/nginx/html
と記載しているのにログでは**/etc/nginx/html**を読み込みに行っているので、locationがうまく読み込まれていないように見えます。 conf.d/default.conf
でコメントアウトしているlocation /
を元に戻すとちゃんと200で返ってくるので、default.conf自体が読み込まれていないわけではなさそうです。- conf.dに余計なファイルがないかは確認しました。
設定ファイル
nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; include /etc/nginx/conf.d/*.conf; }
conf.d/default.conf
server { listen 80; listen [::]:80; server_name localhost; error_page 403 /403.html; error_page 404 /404.html; location /healthz { root /usr/share/nginx/html; } # このコメントアウトを戻すとちゃんと動く #location / { # root /usr/share/nginx/html; #} error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
/usr/share/nginx/html
satken@debian11:~$ ls -la /usr/share/nginx/html drwxr-xr-x 3 satken satken 4096 Jan 23 20:55 . drwxr-xr-x 3 satken satken 4096 Jan 23 21:11 .. -rw-r--r-- 1 satken satken 5 Jan 23 20:42 index.html
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。