Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 1.7 KB

error.md

File metadata and controls

67 lines (49 loc) · 1.7 KB

Error Log

コンテキストパスを変えてみた際のReactとnginxの仕様

React側

  • package.jsonのhomepageを変更することでnpm run startnpm run buildを使ってビルドした際にホストする場所が変わる
  "homepage": "http://localhost/hoge",
npm start
curl localhost:3000/hoge # こっちが推奨だがどっちでも良さそう。
curl localhost:3000/hoge/

nginx側

  • locationaliasを使うことでデプロイするアプリを変えられる。
# 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両方でアプリにアクセスできるようになる。


nginxのエラーページのバージョン情報を消す

  • 以下の条件が揃った状態で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