nginx基础

一、作用
1、反向代理
    a、分向代理:代理服务端,如:用vpn访问网站
    b、反向代理:代理服务端,如:nginx

2、apache、tomcat、nginx:都是http-server,都接收http请求

二、安装与运行
1、安装
    a、tar -zxvf nginx-1.1.4.0.tar.gz
    b、yum install pcre-devel
    c、yum install zlib-devel
    d、./configure --prefix=/data/program/nginx【安装路径(conf、html、logs、sbin)】
    e、make && make install
2、启动停止
    a、启动:sbin/nginx
    b、停止:nginx -s stop
3、访问:ip:80

三、配置说明
cd conf
1、vim nginx.conf
虚拟主机配置
server{
    listen 80;------------------------------------>打开对80端口号的监听
    server_name localhost;------------------------>域名配置
    location / {---------------------------------->匹配规则,根据用户的uri去匹配
        root html;------------------------------->静态资源的访问路径
        index index.html;------------------------->首页文件名称
    }
}
2、基于ip的虚拟主机

3、基于port的虚拟主机
server{
    listen 8080;------------------------------------>打开对8080端口号的监听
    server_name localhost;
    location / {---------------------------------->匹配规则
        root html;------------------------------->静态资源的访问路径
        index index.html;------------------------->首页文件名称
    }
}
4、基于域名的虚拟主机
server{
    listen 8080;------------------------------------>打开对8080端口号的监听
    server_name www.sunxj1222.com;
    location / {---------------------------------->匹配规则
        root html;------------------------------->静态资源的访问路径
        index index.html;------------------------->首页文件名称
    }
}
5、location匹配规则:
    a、精准匹配:location=/index
    b、前缀匹配:location ^~ /info
    c、正则匹配:location ~ \.(gif|png|css)$
    d、通通匹配:location / {}
    
6、改动配置不需要重启,重新加载就好,不用重启nginx:./nginx -s -reload
7、验证配置语法是否有问题:./nginx -t
8、查看nginx的版本号:./nginx -Vg

    
四、模块
反向代理、email、nginx core
1、模块分类
    a、核心模块:ngx_http_core_module
    b、标准模块:http模块
    c、第三方模块
2、ngx_http_core_module
server {
    listen port
    server_name
    location
    error_page:500 501 /50x.html------------------------>定义错误码的页面
    location = /50x.html{
        root html;
    }
    ...
}
3、ngx_http_access_module-------------->访问控制模块,deny或allow
location / {
    deny all;
    allow all;
}
4、http_stub_status_module------------->查看nginx状态的信息,比如client端请求了多少次,server端响应了多少次请求
location /status{
    stub_status;
}
5、http_random_index_module------------->随机选择一个页面响应
location /random{
    random_index on;
}
6、添加第三方模块
    a、原理安装的配置,必须在安装新模块的时候加上
    b、不能直接make install
(1)、安装
    a、方式一:./configure --perfix=/安装目录 --add-module=/第三方模块的目录
    b、方式二:./configure --prefix=/data/program/nginx --with-http_stub_status_module --with-http_random_index_module
    c、make
    d、cp objs/nginx ../nginx/sbin/nginx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值