How does nginx find the default root directory (root html)
nginx exit configuration
server {
listen 80;
server_name 127.0.0.1;
location / {
root html; # 这是一个相对路径
}
error_page 404 /404.html; #当状态码为400则转到/404.html
error_page 500 502 503 504 /50x.html; #当状态码为50x.. 则转到/50x.html
location = /50x.html {
root html;
}
}
The nginx configuration file is on the system /etc/nginx/nginx.conf
, and index.html
the location of the service is /var/lib/nginx/html/index.html
. Now, look at the above configuration, how is nginx found according to the configuration /var/lib/nginx/html/index.html
?
answer
This involves the mechanism by which nginx finds relative paths. nginx will put --prefix
the splicing in front of the relative path to form a complete path together.
--prefix
The installation may be different in different environments. nginx -V
You can view the relevant configuration by
nginx -V
nginx version: nginx/1.24.0
built with OpenSSL 3.1.0 14 Mar 2023
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body
......
......
You can see the above --prefix=/var/lib/nginx
, so the full path of the html that nginx looks for at this time is/var/lib/nginx/html