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协议
$status HTTP请求状态
$body_bytes_sent 发送给客户端文件内容大小
$http_referer url跳转来源
$http_user_agent 用户终端浏览器等信息
$http_x_forwarded_for
$upstream_status upstream状态
$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;
        }

相关推荐

  1. centos7 安装php82

    2023-12-20 11:22:01       40 阅读
  2. CentOS 7 安装 Nginx

    2023-12-20 11:22:01       59 阅读
  3. CentOS 7 安装 Nginx

    2023-12-20 11:22:01       50 阅读
  4. Centos 7 安装Nginx

    2023-12-20 11:22:01       57 阅读
  5. centos7安装nginx

    2023-12-20 11:22:01       42 阅读
  6. centos7 安装 nginx

    2023-12-20 11:22:01       29 阅读
  7. Centos7安装nginx

    2023-12-20 11:22:01       33 阅读
  8. Centos系统上nginx安装

    2023-12-20 11:22:01       45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-20 11:22:01       91 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-20 11:22:01       97 阅读
  3. 在Django里面运行非项目文件

    2023-12-20 11:22:01       78 阅读
  4. Python语言-面向对象

    2023-12-20 11:22:01       88 阅读

热门阅读

  1. rpc和消息队列区别

    2023-12-20 11:22:01       51 阅读
  2. js对象转换为excel,excel转换为js对象

    2023-12-20 11:22:01       64 阅读
  3. MATLAB 平面拟合并旋转到水平面 (43)

    2023-12-20 11:22:01       52 阅读
  4. Https图片链接下载问题

    2023-12-20 11:22:01       66 阅读
  5. Https接口调用问题

    2023-12-20 11:22:01       51 阅读