0
エクスプレスサーバーをポート3000で実行しようとしています。サーバーのIPにアクセスすると、htmlページを読み込むことができますアセットを見つけることができないようです(私がリンクしている.jsと.cssファイルを持っています - これはpublic
のindex.htmlと同じディレクトリにあります)。私は私の設定で何かを見逃していますか?expressとnginx - htmlファイルをロードしますが、アセットを提供できません
特急セットアップ
const express = require('express');
const path = require('path');
const app = express();
const PORT = 3000;
app.use('*',
express.static(path.join(__dirname, '..', 'public', 'index.html')));
app.get('*', (req, res) => {
res.sendFile((path.join(__dirname, '..', 'public', 'index.html')));
});
app.listen(PORT,() => {
console.log(`Listening on http://localhost:${PORT}...`)
});
nginxの設定あなたのnginxの構成では
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/my_site/public;
index index.html index.htm index.nginx-debian.html;
server_name _;
location/{
try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
'index.html'ファイルがnginxによって提供されているかどうかを確認するには、' app.use'と 'app.get'をexpressから削除してみてください。 – squgeim