(syntax)nginx
2022-09-01 00:00:00

nginx

  • 轻量级http服务器 事件驱动的异步非阻塞处理方式

  • 目录

    • 文件目录
      • 项目文件
        • /etc/nginx/nginx.conf 核心配置文件
        • /etc/nginx/conf.d/default.conf 默认http服务器配置文件
      • 配置文件目录
        • nginx.conf 主配置文件
          • /usr/local/etc/nginx/nginx.conf
          • /etc/nginx/nginx.conf
        • servers 服务文件 /usr/local/etc/nginx/servers/
        • 默认http服务器配置文件
          • /etc/nginx/conf.d/default.conf 默认http服务器配置文件
            • listen 监听端口
            • location / {} 服务默认启动目录
      • 安装文件目录
        • /usr/local/Cellar/nginx/版本/html ==> /usr/local/var/www
      • 默认网站的目录 mac /usr/local/var/www Linux /usr/share/nginx/html
      • 系统host位置 /private/etc/hosts
  • 常用命令 nginx \ nginx -s stop\reopen\reload services start\stop\restart nginx

    • ps -ef | grep nginx 查看nginx目录信息
    • netstat -tlnp 查看端口号占用情况
    • nginx -t
    • 启动 nginx、 systemctl start nginx.service 、services start nginx
    • 版本 -v 帮助 -h
    • 停止
      • 立即停止服务 nginx -s stop
      • 从容停止服务 nginx -s quit
      • killall方法杀死进程 killall nginx
      • systemctl停止 systemctl stop nginx.service
    • 重启
      • nginx -s reopen 重新启动
      • nginx -s reload 重新载入配置文件
      • systemctl restart nginx.service
      • services restart nginx
      • nginx -s quit 退出(处理完事情走)
      • nginx -c filename 指定配置文件
  • 配置

  • 功能

    • 错误页 /etc/nginx/conf.d/default.conf

    • 访问权限

      1
      2
      3
      4
      5
      6
      7
      8
      9
      location =/img{
      allow all;
      }
      location =/admin{
      deny all;
      }
      location ~\.php${
      deny all;
      }
    • 虚拟主机

      • 端口 Nginx监听多个端口,根据不同的端口号,来区分不同的网站

        • nginx.conf

        • default.conf

          1
          2
          3
          4
          5
          6
          server{
          listen 8001;
          server_name localhost;
          root /usr/share/nginx/html/html8001;
          index index.html;
          }
        • conf.d文件夹下新建文件 端口数.conf 8001.conf

      • ip 基于ip的虚拟主机

        1
        2
        3
        4
        5
        6
        server{
        listen 80;
        server_name 112.74.164.244;
        root /usr/share/nginx/html/html8001;
        index index.html;
        }
    • 正向代理(梯子) 反向代理

      • etc/nginx/con.d/8001.conf

        1
        2
        3
        4
        5
        6
        7
        server{
        listen 80;
        server_name nginx2.jspang.com;
        location / {
        proxy_pass http://jspang.com;
        }
        }
    • 适配PC或移动设备

    • Gzip压缩配置

    • 负载均衡

    • 常用全局变量

    • 静态资源服务、通过本地文件系统提供服务

    • API 服务、权限控制、减少应用服务器压力

上一页
2022-09-01 00:00:00
下一页