CentOS 8.2 安装 nginx-1.18.0

1、下载

wget http://nginx.org/download/nginx-1.18.0.tar.gz

2、安装依赖包

yum install gcc -y 
yum install pcre pcre-devel -y
yum install zlib zlib-devel -y
yum install openssl openssl-devel -y

3、编译&安装

./configure --prefix=/opt/nginx
make && make install

4、配置文件

nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

5、启停

sbin/nginx			# 启动
sbin/nginx -s stop	# 停止
sbin/nginx -V		# 查看版本
# 验证
curl -i http://XXXXXX:8080

6、nginx.conf详解

6.1 Log_format

参数描述
$remote_addr客户端地址
$remote_user客户端用户名称
$time_local访问时间和时区
$request请求的URI和HTTP协议
$statusHTTP请求状态
$body_bytes_sent发送给客户端文件内容大小
$http_refererurl跳转来源
$http_user_agent用户终端浏览器等信息
$http_x_forwarded_for
$upstream_statusupstream状态
$upstream_addr后台upstream的地址
$request_time整个请求的总时间
$upstream_response_time请求过程中,upstream响应时间
    log_format  main  '$remote_addr|$remote_user|[$time_local]|"$request"'
                      '|$status|$request_time|$body_bytes_sent|"$http_referer"'
                      '|"$http_user_agent"|"$http_x_forwarded_for"';

6.2 Location

参数说明
=表示精确匹配
^~表示匹配URL路径,以xx开头
~正则匹配,区分大小写,以xx结尾
~*正则匹配,不区分大小写,以xx结尾
!~和!~*正则不匹配,区分大小写和不区分大小写,以xx结尾
/通用匹配,任何请求都会匹配到。

【匹配顺序】:

  1. 首先精确匹配 =

  2. 其次以xx开头匹配^~

  3. 然后是按文件中顺序的正则匹配

  4. 最后是交给 / 通用匹配。

【1】alias是一个目录别名的定义,root则是最上层目录的定义。

        location /check/ {
        	# 访问/check/目录下文件,nginx去html目录下找文件
            alias   html;
            index  index.html;
        }
        location /check/ {
        	# 访问/check/目录下文件,nginx去html/check/目录下找文件
            root   html;
            index  index.html;
        }

【2】代理

        location / {
            proxy_set_header Host $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_pass http://10.207.28.134:5061;
            root   html;
            index  index.html index.htm;
        }

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值