【发布时间】:2020-02-21 11:44:59
【问题描述】:
我正在尝试向访问通配符子域的用户显示子文件夹: abc.example.com -> example.com/xyz
这个 NGINX 服务器块代码正在运行:
server {
# server name with regexp
server_name ~^(?<sub>[^.]+)\.example\.com$;
# this server catches all requests to xxxx.example.com
# and put "xxxx" to $sub variable
location / {
# finally we want to request different URI from remote server
proxy_pass http://localhost:8000;
# proxy_redirect will rewrite Location: header from backend
# or you can leave proxy_redirect off;
proxy_redirect http://localhost:8000 http://$sub.localhost:8000;
}
[certbot code]
}
(发现问题5249883)。
但是当用“https:localhost:8000/xyz”替换proxy_pass值“https://localhost:8000”时,我得到这些错误和一个空白页:
Uncaught SyntaxError: Unexpected token '<'
在socket.io.js 和commons.js 中。
我在 example.com 上运行的应用是使用 React/Gatsby 构建的。 example.com/demo 正在运行。
编辑:我输入了错误的错误信息,当我尝试不同的东西时出现了这些错误。
【问题讨论】:
-
尝试
https://localhost:8000/xyz/而不是https://localhost:8000/xyz -
@IvanShatsky 我得到了同样的结果
-
我认为您遇到了我试图描述的问题here。
-
这两个资产的正确 URL 是什么?例如。他们是
/xyz/socket.io.js还是/socket.io.js? -
@IvanShatsky 感谢您的链接!例如,我使用 /api 的位置前缀,效果很好。我尝试在此博客中设置位置前缀,但随后获得了放入 /var/[domain]/html 目录的示例 html 页面。这是为什么?除此之外,如果我使用位置前缀,那不是只是将我的主应用程序从“/”移动到“/someDirectory”,而我仍然必须使用 location_pass 来访问我的子文件夹吗?我不确定您是否看到我关于错误的更新。看来,服务器为 socket.io.js 提供了 html 而不是 js (?)。你知道为什么吗?
标签: reactjs nginx server config gatsby