nginx如何找到默認(rèn)根目錄(root html)
nginx的出場配置
server {
listen 80;
server_name 127.0.0.1;
location / {
root html; # 這是一個(gè)相對路徑
}
error_page 404 /404.html; #當(dāng)狀態(tài)碼為400則轉(zhuǎn)到/404.html
error_page 500 502 503 504 /50x.html; #當(dāng)狀態(tài)碼為50x.. 則轉(zhuǎn)到/50x.html
location = /50x.html {
root html;
}
}
系統(tǒng)上nginx配置文件在/etc/nginx/nginx.conf
,服務(wù)index.html
的位置是/var/lib/nginx/html/index.html
?,F(xiàn)在,看看上面的配置,nginx是如何根據(jù)配置找到/var/lib/nginx/html/index.html
?
解答
這就涉及到nginx查找相對路徑的機(jī)制。nginx會把--prefix
拼接到相對路徑的前面,共同組成一個(gè)完整的路徑。
--prefix
在不同的環(huán)境中安裝可能都是不一樣的。可以通過nginx -V
查看到相關(guān)配置文章來源:http://www.zghlxwxcb.cn/news/detail-605226.html
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
......
......
可以看到上面--prefix=/var/lib/nginx
,因此此時(shí)nginx查找的html的完整路徑是 /var/lib/nginx/html
文章來源地址http://www.zghlxwxcb.cn/news/detail-605226.html
到了這里,關(guān)于nginx如何找到默認(rèn)根目錄(root html)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!