配置文件位置
- nginx安裝時(shí)設(shè)置的的
prefix
參數(shù)指定了nginx程序目錄,如果程序目錄默認(rèn)為/usr/local/nginx
,那么配置文件默認(rèn)為/usr/local/nginx/conf/nginx.conf
。
配置文件結(jié)構(gòu)
- 簡單指令,以分號(hào)結(jié)尾。如
worker_processes 1;
。 - 塊指令:將一組簡單指令組合在一起,用{}對塊指令分組。如:
events {
worker_connections 1024;
}
- 包含指令:將一些指令單獨(dú)放到一個(gè)文件中,在主配置文件中用
include
包含這些單獨(dú)的配置文件。如include /usr/local/nginx/conf/80.conf;
。 - 一個(gè)http模塊可以有多個(gè)server,一個(gè)server也可以有多個(gè)location。
- nginx中有些指令(如root、index)可以出現(xiàn)在不同的層級中,最內(nèi)層的指令會(huì)覆蓋上一層的指令,如以下的配置中
/test/
會(huì)使用/home/userroot/2
為根目錄,使用b.html
為默認(rèn)文件;其它路徑會(huì)使用server
中root
配置的/home/userroot/1
為根目錄,使用a.html
為默認(rèn)文件。
http {
server {
listen 8099;
server_name 192.168.1.199;
root /home/userroot/1;
index a.html;
location /test/ {
root /home/userroot/2;
# http://192.168.1.199:8099/test/防問的是/home/userroot/2/test/b.html文件
index b.html;
}
}
}
閱讀原文:原文鏈接
該文章在 2025/7/1 23:40:29 編輯過