検索条件
お知らせ
現在サイトのリニューアル作業中のため、表示が崩れているページが存在することがあります。
Next.js 11から12にしたらHMRが死んだので復活させるための設定を書いておく
| Env |
Ver |
| nginx |
Windows-1.21.4 |
| Next.js |
12.0.4 |
標準状態でnpx nextを叩いた状態を想定している
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:3000;
}
}
~で正規表現を書けるので後は普通に書くだけ
- ポイントとしては
/foo/のような正規表現リテラルではなく、grepのような書き方をする
location ~ (/foo|/bar) {
パスFooでは直にリバプロしたいけど、Barではローカルを見てからリバプロしたいときなどに使える
location @prox {
proxy_set_header Authorization "Basic xxxxxxxxxxxxxxxxxxxxx==";
proxy_pass https://example.com;
}
# 直遷移させたい
location ^~ /foo {
try_files /dev/null @prox;
}
# 内部に当ててから遷移したい
location ^~ /bar {
try_files $uri @prox;
}
Proxy headerを設定しないとiOS Safari環境で上手くアクセスできないケースがあるのでやる設定
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
location @prox {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://example.com;
}
nginxの設定ファイルを更新したのに読み込んでくれないときの対処法
- 次のようにnginxのリロードや再起動をしても通じないとき
nginx -s reload
nginx -s stop -> nginx
- 次のコマンドを流すとプロセスが綺麗に死んでくれて再読込できることがある
sudo kill -HUP $(cat /var/run/nginx.pid)