Nginx 使用笔记

  • 反向代理
  • 负载均衡
  • 动静分离

架构的核心思想——分层
VPN 正向代理

Nginx

内存占用小,支持5万的高并发

启动需要英文目录

  1. linux 中 解压执行 configure 文件
  2. 未报错 执行 makemake install
  3. whereis nginx 找到安装目录
  4. sbin 下可启动 nginx;conf 下可配置 nginx;

error: C compiler cc is not found

yum -y install gcc-c++ autoconf automake

常见出错及解决方案

error: the HTTP rewrite module requires the PCRE library

 yum install -y pcre pcre-devel

error: the HTTP gzip module requires the zlib library

yum install -y zlib zlib-devel

基本命令

./nginx # 启动
./nginx -s stop # 停止
./nginx -s quit # 安全退出
./nginx -s reload # 重载

配置 nginx.conf

80 rewrite 433

root nginx前端页面路径

http {
  # http 配置
  upstream xxxx {
    # 负载均衡设置
    server 主机 weight=1;
  }
  server {
    listen 80;
    server_name localhost;
  }
    server {
      listen 443;
      server_name localhost;
      location / {
        root /home/xx; # 前端静态文件;
        index  index.html index.htm;
      }
      location /api {
        proxy_pass http://127.0.0.1:8080; # 配置代理
        rewrite "^/api/(.*)$" /$1 break;
      }
    }
}

location :一个server下可以有多个location ,用来匹配 同一个域名下不同uri的访问
location [=|~ | ~* |^~|@] /uri/ { - }
普通 无开头引量字符或以 = 开头表示普通字符匹配
正则~~ * 开头表示正则匹配,~ * 表示不区分大小写

Redis - Session 会话共享

posted @ 2023-02-27 13:48  海胆Sur  阅读(15)  评论(0)    收藏  举报  来源