nginx是由一系列核心功能模块组成,并且你还可以加入自己写的模块进去。
配置文件
配置文件是nginx最重要的操作入口
大致的格式如下:
配置块{
各种指令(比如worker_processes 1;include mime.types;)
子配置块{
又是各种指令
子子配置块{
}
}
}
注意点:
1、配置文件最外层的配置块叫做main
,本身也是一个大block。
2、核心指令 http://nginx.org/en/docs/ngx_core_module.html#directives
挑着学
我们先来重点学习http模块,并优先学习其子模块server
http{ #用来处理http协议相关
server{ #定义虚拟主机相关
listen 80;
server_name xxoo.com
location / { #处理请求
#这里还有指令,比如目录路径
}
location xxoo{ #处理请求
}
}
}
http://nginx.org/en/docs/http/ngx_http_core_module.html#server
配置一个静态网站
server{
listen 80;
server_name localhost;
location /{
root /var/www/html; #网站目录
index index.html; #默认首页
}
}
怎么配置多网站?加一个server
server{
listen 80;
server_name localhost;
location /{
root /var/www/html; #网站目录
index index.html; #默认首页
}
}
server{
listen 80;
server_name localhost;
location /{
root /var/www/abc;
index index.html;
}
}