確認環境
| Env | Ver |
|---|---|
| nginx | 1.19.8 |
サンプルコード
~で正規表現を書けるので後は普通に書くだけ- ポイントとしては
/foo/のような正規表現リテラルではなく、grepのような書き方をする
- ポイントとしては
location ~ (/foo|/bar) {
パスFooでは直にリバプロしたいけど、Barではローカルを見てからリバプロしたいときなどに使える
| Env | Ver |
|---|---|
| nginx | 1.19.8 |
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環境で上手くアクセスできないケースがあるのでやる設定
| Env | Ver |
|---|---|
| nginx | 1.19.8 |
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 -s reloadnginx -s stop -> nginxsudo kill -HUP $(cat /var/run/nginx.pid)| Env | Ver |
|---|---|
| Windows | 10 pro |
| PHP | 8.0.2 NTS Visual C++ 2019 x64 |
| nginx | 1.19.8 |
nginx.confを開きFastCGI server listening on 127.0.0.1:9000辺りに次の設定をする
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
.phpファイルを配置nginxを起動php-cgi.exe -b 127.0.0.1:9000.phpファイルにアクセス