Expressアプリケーションはブラウザに静的ファイルを読み込むことはできませんが、カールで動作します。私はウェブサーバーとしてnginxを使用します。アプリケーションは正常に動作しますが、静的ファイルはありません。私はここで間違って何をしていますか?Express/Nginxで静的ファイルを読み込めません
App.js
...
App.use(cors())
App.use("/data", express.static(__dirname + '/data'));
App.use('/api', require('./routes/api'))
App.listen(1337)
nginxの
server
{
listen x.x.x.x:80;
server_name example.com www.example.com ;
location /api {
proxy_pass http://x.x.x.x:1337;
...
}
location/{
return 301 https://$server_name$request_uri;
}
}
server
{
listen x.x.x.x:443 ssl;
server_name example.com www.example.com ;
root /path/to/public_html;
index index.php index.html index.htm;
ssl on;
location /api {
add_header X-Cache "HIT from Backend";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://x.x.x.x:1337;
...
}
}
カールはokです:
http://127.0.0.1:1337/data/pic.png
しかし、ブラウザではありません。
http://example.com/api/data/pic.png
ルータ:
App.use('/api', require('./routes/api'))
http://x.x.x.x:1337/data/pic.png
にリダイレクトされます、このnginxの設定ファイルを試してみて、私のルータである@Farnabaz、あなたのブラウザのアドレス – Farnabazに/ api' '削除 – user1788781