- package.jsonのhomepageを変更することで
npm run start
やnpm run build
を使ってビルドした際にホストする場所が変わる
"homepage": "http://localhost/hoge",
npm start
curl localhost:3000/hoge # こっちが推奨だがどっちでも良さそう。
curl localhost:3000/hoge/
location
とalias
を使うことでデプロイするアプリを変えられる。
# nginx.conf
# location /hoge/にすると403 Forbiddenになる。
location /hoge {
alias /usr/share/nginx/html;
}
curl localhost/hoge/ # 成功
curl localhost/hoge # Unable to connect
Note
package.jsonのhomepage: ""
の状態だと,localhost/hoge/とlocalhost両方でアプリにアクセスできるようになる。
- 以下の条件が揃った状態でlocalhost/hogeにアクセスすると403 Forbiddenが発生する。
"homepage": "http://localhost/hoge",
# nginx.conf
location /hoge/ {
alias /usr/share/nginx/html;
}
- エラーページのバージョンを抑止するには
server_tokens off;
を設定する。
# nginx.conf
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
server_tokens off; # Error page version off