是一个高性能的反向代理服务器 正向代理代理的是客户端 反向代理代理的是服务端
安装:
启动和停止
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}基于ip的虚拟主机
基于端口号的虚拟主机
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html;
}
}基于域名的虚拟主机
www.guapaoedu.com / ask.gupaoedu.com / git.gupaoedu.com / bbs.gupaoedu.com
server {
listen 80;
server_name www.gupaoedu.com;
location / {
root html;
index index.html;
}
}
server {
listen 80;
server_name bbs.gupaoedu.com;
location / {
root html;
index bbs.html;
}
}
server {
listen 80;
server_name ask.gupaoedu.com;
location / {
root html;
index ask.html;
}
}location [= | ~* | ^~ ] /uri/ {…}
location = /uri 精准匹配 location ^~ /uri 前缀匹配 location ~ /uri location / 通用匹配
1 location = /
2 location = /index
3 location ^~ /article/
4 location ^~ /article/files/
5 location ~ \.(gif|png|js|css)$
6 location /
http://192.168.11.154/
http://192.168.11.154/index ->2
http://192.168.11.154/article/files/1.txt ->4
http://192.168.11.154/mic.png ->5location =/ {
}
location / {
}
location ~* \.(gif|....)${
}模块分类
server{
listen port
server_name
root ...
}实现基于ip的访问控制功能 1、allow address | CIDR | unix: | all; 2、deny address | CIDR | unix: | all; 自上而下检查,一旦匹配,将生效,条件严格的置前
如何添加第三方模块
configure --prefix=/data/program/nginx安装方法
./configure --prefix=/安装目录 --add-module = /第三方模块的目录
./configure --prefix=/data/program/nginx --with-http_stub_status_module --with-
http_random_index_module
cp objs/nginx $nginx_home/sbin/nginxlocation /status {
stub_status;
}Active connections:当前状态,活动状态的连接数 accepts:统计总值,已经接受的客户端请求的总数 handled:统计总值,已经处理完成的客户端请求的总数 requests:统计总值,客户端发来的总的请求数 Reading:当前状态,正在读取客户端请求报文首部的连接的连接数 Writing:当前状态,正在向客户端发送响应报文过程中的连接数 Waiting:当前状态,正在等待客户端发出请求的空闲连接数
随机显示主页 一般情况下,一个站点默认首页都是定义好的index.html、index.shtml等等,如果想站点下有很多页面想随机展示给 用户浏览,那得程序上实现,很麻烦,使用nginx的random index即可简单实现这个功能,凡是以/结尾的请求,都 会随机展示当前目录下的文件作为首页
location / {
root html;
random_index on;
index index.html index.htm;
}