【发布时间】:2017-02-24 00:56:08
【问题描述】:
我尝试在 nginx 上设置一个 React 应用程序,但在从子目录提供静态文件时遇到了问题
我的文件树是这样的:
/var/www/
antoinedeveyrac.io/
...
react/
...
build/
index.html
static/
js
*.js
css
*.css
我的配置文件是:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
include snippets/ssl-antoinedeveyrac.io.conf;
include snippets/ssl-params.conf;
root /var/www/antoinedeveyrac.io/html;
index index.html index.htm index.nginx-debian.html;
server_name antoinedeveyrac.io www.antoinedeveyrac.io;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ /.well-known {
allow all;
}
location /react {
alias /var/www/react/build;
try_files $uri $uri/ =404;
autoindex off;
index index.html;
}
}
所以当我点击https://antoinedeveyrac.io/react 时,我有那些 404 错误,这意味着 nginx 不明白我想从https://antoinedeveyrac.io/react/static/... 而不是https://antoinedeveyrac.io/static/... 提供文件
如何修复我的配置文件以匹配子目录中的静态文件?非常感谢:)
【问题讨论】: