乐云主机笔记

  • 首页
  • 学习记录
  • 资源下载
  • 新手教程
  • 其他
  • 脚本源码
  • 自用主机
  • 主机优惠
  • 域名优惠
  • 网赚项目

  1. 首页
  2. 新手教程
  3. 正文

Nginx反代并将静态文件/首页/根目录重定向到子目录的方法

2023年 5月 30日 1009点热度 0人点赞 0条评论

我有一个运行在http://192.168.0.2:8080/的应用程序。 index.html页面位于/web文件夹中,它在/css处请求静态文件(例如css)。
我想使用nginx作为反向代理,并让myapp.mydomain.com重定向到我的应用程序。 我在我的nginx.conf有以下配置:

server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location / {
proxy_pass http://192.168.0.2:8080/web/;
index index.html index.htm;
}
}

但它不适用于css文件,因为它在/web/css查找它们。 我的解决方法是以这种方式配置我的nginx.conf (不带/web ):

server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location / {
proxy_pass http://192.168.0.2:8080/;
index index.html index.htm;
}
}

并且每次请求http://myapp.mydomain.com/web 。
但我希望能够请求http://myapp.mydomain.com/并让nginx管理。


方法是:
据我所知,你有一个工作配置, 唯一的问题是,你想URL http://myapp.mydomain.com/被映射到http://192.168.0.2:8080/web/ 。
您的工作配置是:

server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location / {
proxy_pass http://192.168.0.2:8080/;
index index.html index.htm;
}
}

最简单的解决方案是为/ URI添加完全匹配。 如:

server {
listen 80;
server_name myapp.mydomain.com;
satisfy any;
location = / { rewrite ^ /web/; }
location / {
proxy_pass http://192.168.0.2:8080/;
index index.html index.htm;
}
}

关键代码是:
location = / { rewrite ^ /web/; }

标签: 反代 子目录
最后更新:2023年 5月 30日

wangzhe12588

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

归档

  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 7 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 9 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 6 月
  • 2023 年 5 月
  • 2023 年 4 月
  • 2023 年 3 月
  • 2023 年 2 月
  • 2023 年 1 月
  • 2022 年 12 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 7 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 8 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2019 年 2 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 9 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月

分类

  • 主机优惠
  • 其他
  • 域名优惠
  • 学习记录
  • 新手教程
  • 网赚项目
  • 脚本源码
  • 自用主机
  • 资源下载

COPYRIGHT © 2021 Letcloud.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备15031609号-3