【发布时间】:2020-12-07 21:44:24
【问题描述】:
我尝试将我构建的 react 应用程序作为我的域的子目录运行(例如:mydomain.com/apps/one/client)。它使用我提供的 nginx 配置在 docker 容器中运行:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
该应用程序使用 docker compose 运行,我将 80 容器端口映射到服务器机器中的 3041。然后在我的服务器机器上,我有这样的 nginx 配置:
server {
listen 443 ssl;
client_max_body_size 0;
server_name mydomain.com;
(cert settings)[...]
location /apps/one/client {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:3041/apps/one/client;
}
(other locations config)[...]
}
但我在控制台应用程序Uncaught SyntaxError: Unexpected token '<' 中遇到错误。我尝试了很多不同的变体,但我仍然无法实现我想要的 - 在我的域路径的子目录上运行应用程序。在这种情况下,nginx 配置应该如何?非常感谢您的帮助。
【问题讨论】:
-
尝试在 Stack Exchange 网络的另一个网站 Server Fault 提问,专门针对与服务器相关的问题。
标签: docker nginx proxy subdirectory