我有一个 ReactJS 应用程序,如果使用以下代码从子目录的根目录提供,它可以正常工作:
server {
listen 80;
server_name sub.domain.net;
root /var/www/vhosts/sub.domain.net/httpdocs;
location / {
try_files $uri $uri/ /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我想从主服务器提供此服务domain.net,并在之前的所有尝试中都出错。这是我所拥有的,它绝对不起作用,相同的 ReactJS 文件位于根目录外:
server {
listen 80;
server_name domain.net;
root /var/www/vhosts/domain.net/httpdocs;
location / {
try_files $uri $uri/ /index.html;
}
location /reactapp {
try_files $uri $uri/ /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
当以这种方式使用它时,我得到一个 Uncaught SyntaxError: Unexpected token < 并且它试图从根而不是目录提供样式表和 .js 。
该应用程序是使用 webpack 构建的,并且可以在子目录之外完美运行。谢谢大家!
nginx ×1