认识nginx配置文件nginx.conf
|
admin
2025年6月28日 22:31
本文热度 18
|
配置文件位置
- nginx安装时设置的的
prefix
参数指定了nginx程序目录,如果程序目录默认为/usr/local/nginx
,那么配置文件默认为/usr/local/nginx/conf/nginx.conf
。
配置文件结构
- 简单指令,以分号结尾。如
worker_processes 1;
。 - 块指令:将一组简单指令组合在一起,用{}对块指令分组。如:
events {
worker_connections 1024;
}
- 包含指令:将一些指令单独放到一个文件中,在主配置文件中用
include
包含这些单独的配置文件。如include /usr/local/nginx/conf/80.conf;
。 - 一个http模块可以有多个server,一个server也可以有多个location。
- nginx中有些指令(如root、index)可以出现在不同的层级中,最内层的指令会覆盖上一层的指令,如以下的配置中
/test/
会使用/home/userroot/2
为根目录,使用b.html
为默认文件;其它路径会使用server
中root
配置的/home/userroot/1
为根目录,使用a.html
为默认文件。
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 编辑过