Nginx 使用笔记
- 反向代理
- 负载均衡
- 动静分离
架构的核心思想——分层
VPN 正向代理
Nginx
内存占用小,支持5万的高并发
启动需要英文目录
- linux 中 解压执行
configure
文件 - 未报错 执行
make
、make install
- whereis nginx 找到安装目录
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 会话共享
内容会不断更新,欢迎批评指正。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· winform 绘制太阳,地球,月球 运作规律
· 上周热点回顾(3.3-3.9)