当前位置: 首页 > news >正文

nginx

1、nginx.conf配置
1.1、作服务器用

    server {# 监听80端口和localhost域名(对域名对应的ip也生效)listen       80;server_name  localhost;# 匹配 /开头 的路径(例如 http:localhost/aaa)location / {# 资源查找路径(http:localhost/aaa.html 匹配 html/aaa.html)root   html;# 路径首页(http:localhost/aaa.html 匹配 html/index.html html/index.htm)index  index.html index.htm;# 请求路径不存在的情况(http:localhost/假设不存在.html 匹配 html/index.html)try_files $uri $uri/ /index.html;}# 匹配 /t开头 的路径(例如 http:localhost/t http:localhost/t/aaa)location /t {# 资源查找路径(http:localhost/t/aaa.html 匹配 html/test/t/aaa.html)root   html/test;# 路径首页(http:localhost/t 匹配 html/test/t/index.html html/test/t/index.htm)index  index.html index.htm;}# 匹配 /t2开头 的路径(例如 http:localhost/t2 http:localhost/t2/aaa)location /t2 {# 资源查找路径(http:localhost/t2/aaa.html 匹配 html/test/aaa.html)alias   html/test;# 路径首页(http:localhost/t2 匹配 html/test/index.html html/test/index.htm)index  index.html index.htm;}# 匹配 /e 的路径(例如 http:localhost/e http:localhost/e/ 不匹配 http:localhost/e/aaa)location = /e {root   html/exc;# 路径首页(http:localhost/e 匹配 html/exc/e/index.html html/exc/e/index.htm)index  index.html index.htm;}# 当服务器返回如下响应码 会返回 /50x.html页面error_page   500 502 503 504  /50x.html;# 匹配 /50x.html 的路径(例如 http:localhost/50x.html)location = /50x.html {# 资源查找路径(http:localhost/50x.html 匹配 html/50x.html)root   html;}}

1.2、作反向代理用

    # 声明后端服务的名称为myhdserver并指定后端真实域名和端口upstream myhdserver {server www.hd.com:8080;}server {# 监听80端口和localhost域名(对域名对应的ip也生效)listen       80;server_name  localhost;# 匹配 /api/开头 的路径(例如 http:localhost/api/aaa)location /api/ {# 转发路径(例如http:localhost/api/aaa 转发为 http:www.hd.com:8080/api/aaa)proxy_pass http://myhdserver;  # 转发到后端服务器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_set_header X-Forwarded-Proto $scheme;}# 匹配 /api/开头 的路径(例如 http:localhost/api/aaa)location /api/ {# 转发路径(例如http:localhost/api/aaa 转发为 http:www.hd.com:8080/aaa)# proxy_pass http://myhdserver/;  # 转发到后端服务器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_set_header X-Forwarded-Proto $scheme;}}

1.3、注意点

            location /t      location /t/
/t/            匹配              匹配 
/t/aaa.html    匹配              匹配
/t             匹配             不匹配
/tabc          匹配             不匹配
/t-xxx         匹配             不匹配
http://www.jsqmd.com/news/318579/

相关文章:

  • 2026年徐州GEO优化公司TOP3深度测评:从技术实力到效果落地选型
  • FreeRTOS 的任务与 Linux
  • 2026年1月衢州GEO优化公司推荐TOP4:从技术实力到行业适配的测评
  • Java毕设选题推荐:基于springboot的酒店客户入住管理系统基于 SpringBoot 的酒店客房管理系统【附源码、mysql、文档、调试+代码讲解+全bao等】
  • 2026年深圳GEO优化服务商推荐TOP5:技术底层到效果落地选型指南
  • 2026年汕头GEO优化公司推荐TOP3:从技术实力到效果落地深度评估
  • 复旦大学:六大顶尖AI模型的安全“体检报告“竟然如此惊人
  • VS Code 插件 - Chinese Converter - 介绍
  • 人大与百度联合攻克AI工具使用的细粒度监督难题
  • 计算机Java毕设实战-基于springboot的酒店客房预定管理系统【完整源码+LW+部署说明+演示视频,全bao一条龙等】
  • 基于深度学习的钢材表面缺陷检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
  • 必看!提示工程架构师规划AI提示系统商业化蓝图
  • 探索 Flow 在 Android 开发中的应用
  • FastAPI 接口限流具体代码示例
  • 【课程设计/毕业设计】基于 SpringBoot 的酒店客房管理系统基于springboot的酒店入住管理系统【附源码、数据库、万字文档】
  • Vue day4
  • 精准选型,全球触达:三大气体检测仪专业B2B平台深度解析与指南
  • Java计算机毕设之基于springboot + vue酒店管理系统基于springboot的酒店管理系统(完整前后端代码+说明文档+LW,调试定制等)
  • Cython:为 Python 注入 C 的速度
  • 巴菲特如何评估企业的竞争优势
  • 【毕业设计】基于springboot的酒店管理系统(源码+文档+远程调试,全bao定制等)
  • 被忽略太久了!这5款办公软件,很多人连名字都没听过!
  • 从Clawdbot到Moltbot:一场被迫的“换壳”,藏着AI开源圈的欢喜与争议
  • 【计算机毕业设计案例】基于springboot健身房预约平台小程序的设计与实现基于SpringBoot的健身房预约平台微信小程序(程序+文档+讲解+定制)
  • 内存检测
  • 【计算机毕业设计案例】基于springboot的智慧酒店业务协同运营平台 酒店管理系统(程序+文档+讲解+定制)
  • Java毕设项目推荐-基于 Spring Boot+MySQL 的酒店运营管理系统基于springboot的酒店管理系统【附源码+文档,调试定制服务】
  • 计算机小程序毕设实战-基于微信小程序+SpringBoot的健身房课程预约选课管理系统基于springboot健身房预约平台小程序的设计与实现【完整源码+LW+部署说明+演示视频,全bao一条龙等】
  • 北大团队:三步法提升视频AI视觉推理能力
  • DeepSeek-AI突破传统视觉:像人类一样“聪明阅读“图像的AI模型