Skip to content

Commit

Permalink
update documents and delete unused comment
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeDTomita committed Aug 6, 2024
1 parent 7044c5b commit ff2ec2a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 13 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,4 @@ pre-commit install

## ERROR LOG

<details>
<summary>今まで詰まったエラー一覧</summary>
<div>
TODO
</div>
</details>
[error.md](./doc/error.md)を参照。
67 changes: 67 additions & 0 deletions doc/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Error Log

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

### React側

- [package.json](../package.json)のhomepageを変更することで`npm run start``npm run build`を使ってビルドした際にホストする場所が変わる

```json
"homepage": "http://localhost/hoge",
```

```shell
npm start
curl localhost:3000/hoge # こっちが推奨だがどっちでも良さそう。
curl localhost:3000/hoge/
```

### nginx側

- `location``alias`を使うことでデプロイするアプリを変えられる。

```
# nginx.conf
# location /hoge/にすると403 Forbiddenになる。
location /hoge {
alias /usr/share/nginx/html;
}
```

```shell
curl localhost/hoge/ # 成功
curl localhost/hoge # Unable to connect
```

> [!NOTE]
> package.jsonの`homepage: ""`の状態だと,localhost/hoge/とlocalhost両方でアプリにアクセスできるようになる。
---

## nginxのエラーページのバージョン情報を消す
- 以下の条件が揃った状態で[localhost/hoge](http://localhost/hoge)にアクセスすると403 Forbiddenが発生する。

```json
"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
```
1 change: 1 addition & 0 deletions doc/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ on:
jobs:
frontend-jest: # ここが指定可能。
```
- TODO: Actionsが通っていてもチェックがRequiredから変更されないので謎。
---
Expand Down
13 changes: 13 additions & 0 deletions doc/github-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

`git push origin master`後に[package.json](./package.json)に設定したurlにアクセスする。


---

## ERROR LOG
Expand All @@ -36,3 +37,15 @@
### テスト用ブランチからもgithub pagesにデプロイしたい

- [repositoryのsettings](https://github.com/RyosukeDTomita/devsecops-demo-aws-ecs/settings/environments)からprotection ruleを変更し,ブランチ名を追加する。

### github pagesの公開範囲をprivateに限定すると謎のドメインにリダイレクトされる

> [GitHub Pagesサイトの可視性を変更する](https://docs.github.com/ja/enterprise-cloud@latest/pages/getting-started-with-github-pages/changing-the-visibility-of-your-github-pages-site)
- privateにすることでOrganaizationsのメンバー限定でサイトを公開することができる。
- ただし,謎のドメインにリダイレクトされる現象が発生。[Private GitHub Pages redirects to internal url](https://github.com/orgs/community/discussions/21581)
- Reactのアプリの場合にはpackage.jsonのhomepageをリダイレクト先に合わせてやる必要がある。

```json
"homepage": "https://effective-pancake-hogehoge",
```
19 changes: 12 additions & 7 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# For more information on configuration, see: http://nginx.org/en/docs/

# fix warning nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
# user nginx;

# user nginx; # fix warning nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
Expand All @@ -29,11 +29,11 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

server_tokens off; # Error page version off


# Use 8080 instead of 80 to avoid the `nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)` when using ECS.
server {
Expand All @@ -42,9 +42,14 @@ http {
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

# localhost/hoge/でアクセス可能にする設定
# location /hoge/にすると403 Forbiddenになる。
# location /hoge {
# alias /usr/share/nginx/html;
# }

error_page 404 /404.html;
location = /404.html {
}
Expand Down

0 comments on commit ff2ec2a

Please sign in to comment.