nginx - Nginx 和代理子域的相对路径
问题描述
我是 Nginx 的新手,正在努力学习。
我有服务器mydomain.com
和我的静态站点my-app.mydomain.com
所有路径都是相对的,所以images/image.png
解析为my-app.mydomain.com/images/image.png
.
我还有第二个应用程序,new-app.mydomain.com
它有同样的问题,试图解决相对路径mydomain.com
我不知道如何解决这个问题,我想避免让所有路径都成为绝对路径。另外,我想要一个解决方案,让我可以继续locations
为新应用程序添加新块并加载资源。我想避免一些可能适用于主应用程序但不适用于其他应用程序的限制。
location /new-app {
proxy_ssl_server_name on;
proxy_pass "mydomain.com";
}
我会很感激帮助。
解决方案
服务器内的位置可以帮助您配置需要在网站子路由上显示的网站/内容。子域需要在单独的 nginx 文件中配置,类似于主域,您可以根据需要在其中添加任意数量的位置。
Nginx 文件:-
mydomain.com
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name mydomain.com;
location / {
proxy_ssl_server_name on;
proxy_pass "mydomain.com"; # This should be server with port on which your server is running on VM(virtual machine)
root /var/www/html/mydomain.com; #In case you want to server static files
try_files $uri $uri/ /index.html;
}
}
new-app.mydomain.com
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name new-app.mydomain.com;
location / {
proxy_ssl_server_name on;
proxy_pass "new-app.mydomain.com"; # This should be server with port on which your server is running on VM(virtual machine)
root /var/www/html/new-app.mydomain.com; #In case you want to server static files
try_files $uri $uri/ /index.html;
}
}
推荐阅读
- python - 熊猫合并具有不同数量多索引的两个数据框
- camera - 如何使用外部 USB 摄像头在 uv4l 上设置帧速率
- text - 如何在 Neo4j 中将选择性查询结果连接为字符串?
- java - Java中的凯撒密码频率分析
- javascript - 使用 Places Autocomplete 在输入中输出城镇/城市而不是完整位置
- git - 错误:尝试重写历史时,pack-objects 死于信号 9517
- angular - 角度输入“必需”总是错误的
- html - 提交后如何保留选定的选项?
- excel - 创建宏以使用某些单元格中预定义的信息来命名 Excel 文件
- javascript - 在 Vue.js 的 v-for 循环中更改此按钮的属性