第9章 — 設定リファレンス

Last Updated: 2026-12-04 09:44 Views: 2

すべてのオプションを網羅したリファレンス(キー、値、既定値、スコープ、例)は docs/options-reference.md にあります。本章は パーサーと同期して維持される完全なクイックリファレンスです。

9.1 ファイルレイアウトと形式

ファイル 内容
conf/wxserver.toml メイン設定: グローバル、HTTP 既定値、アップストリーム、ストリーム、WAF、モジュール
conf/manager.toml コンソールのスイッチ、リスナー、ログイン保護、JWT、パスワードハッシュ(0600)
conf/acme.toml ACME ポリシーと DNS 資格情報。0600、マスターのみ
conf/cert.toml 証明書索引。サイトは ssl.cert 経由で参照
conf/vhost/*.toml サイトごとに 1 ファイル、http.include で集約
conf/certs/ 証明書と秘密鍵
conf/mime.toml、conf/*_params.toml、conf/waf/ 補助ファイル(MIME テーブル、パラメーターテンプレート、WAF ルール/キャッシュ)
  • include には 2 つのスコープがあります。トップレベルの include はフラグ メント全体を取り込み(http/modules を含められます)、 http = { include = [...] } はサイトフラグメントを集約します(フラグメント は servers/upstreams/map/geo/split_clients をルートに記述します)。 相対パスは各インクルード元ファイルを基準に解決され、設定ディレクトリ内の 相対 .toml パスのみ許可されます(絶対パス、..、シンボリックリンクによる 逸脱は拒否されます)。
  • manager.toml / acme.toml はプライベートです。メイン設定または任意の include に manager/acme トップレベルブロックがあるとエラーになります (include = ["*.toml"] でも同様)。
  • 保存される設定は TOML 1.1 の JSON スタイル複数行インラインテーブルを使用 します。TOML 1.0 のみのバリデータは誤ったエラーを報告する可能性があります。 wxserver -t を信頼してください。
  • wxserver -t -c <config> で検証し、-s reload または POST /api/config/reload でホットリロードします。

9.2 global ブロック

キー 型 / 値 既定値 説明
user / group 文字列 プラットフォーム既定 ワーカーアカウント。root は拒否(デバッグ: WXSERVER_ALLOW_ROOT=1)
worker_processes 整数 / "auto" 1 ワーカー数
worker_cpu_affinity "auto" / CPU ID / cpumask 未バインド ワーカーごとの CPU アフィニティ(Linux)
log_cpu_affinity CPU ID 未バインド マスターのログスレッドのアフィニティ(Linux)
pid パス run/wxserver.pid PID ファイル
shared_state パス run/wxserver.shm(既定で有効) 共有状態ファイル(mmap、アップストリームの DNS キャッシュを含む)。空文字列でプロセス内状態にフォールバック。既定パスの失敗は警告してフォールバック
shared_state_size サイズ 32m 共有状態ファイルのサイズ(有効時)
log_socket パス run/wxserver-log.sock マルチワーカーのログ IPC ソケット
log_queue_size 行数、0 = 同期 アクセスログありで 1024、なければ 64 ログキューの長さ。1 スロット約 320B。起動時に固定
log_flush_interval_ms ミリ秒 200 最大フラッシュ間隔。プロデューサーは破棄せずブロック
server_tokens bool true false はバージョンを隠す(旧 "on"/"off" も引き続き受け付け)
graceful_timeout_sec 秒 30 グレースフルシャットダウンの待機
error_page_root ディレクトリ 組み込みページディレクトリ 相対 file: ターゲットの検索ルート/境界(server > http > global)
log_redact / log_redact_keys bool / 配列 true / [] アクセスログのクエリパラメーターの秘匿(password/token/secret/session/otp など)
error_log ログオブジェクト path 未設定時は出力なし エラーログ。スコープ global/server/location、§9.11 を参照

9.3 http ブロック

キー 型 / 値 既定値 説明
include glob 配列 [] サイトフラグメントを集約
client_max_body_size サイズ、"0" は無制限 10m ボディ上限。server/ロケーションで上書き可
sendfile bool true 静的ゼロコピー。平文 HTTP/1.1 の静的配信のみ
static_meta_cache_ms ミリ秒 0 静的 stat キャッシュの TTL
http2 / http3 bool 有効 false は強制オフ(サイトレベルの true より優先)。実際の有効化は listen の http2/http3 で決まる
ktls bool false Linux kTLS オフロード(AES-GCM)、自動フォールバック
max_header_bytes バイト 1m ヘッダー上限(431)
read_header_timeout_sec 秒 30 ヘッダー読み取りタイムアウト
idle_timeout_sec 秒 75 keep-alive のアイドルタイムアウト
access_log パス/オブジェクト 未設定 = 記録なし グローバルアクセスログ。{ enabled = false } で閉じる、§9.11 を参照
default_type MIME — 実行時には使用されません。サイト/ロケーションレベルを使用
disabled_modules 名前 [] グローバルに無効化するモジュール(サイトのリストとマージ)
gzip オブジェクト オフ グローバル gzip(§9.10 を参照)
error_page マップ 404→file:4xx.html、5xx→file:5xx.html ターゲット: file: / root: / link:(継承は location > server > http)
servers / upstreams / map / geo / split_clients / proxy_cache_path 配列 — §9.5–§9.7 を参照

proxy_cache_path のフィールド: name(必須)、path(設定するとディスク キャッシュ、それ以外はメモリ)、max_size_mb(0 = 無制限)、inactive_sec。 単一エントリのキャッシュ上限は 16MB です。

9.4 派生変数(map / geo / split_clients)

キー 説明
map { name = "$x", source = "$y", default, hostnames, entries }。キー: 完全一致、~regex、default。最初の一致が優先
geo { name = "$x", default, entries }。キー: CIDR / 裸の IP / default。最長プレフィックスが優先
split_clients { name = "$x", source = "$y", entries }。キー "N%"、ソースの fnv ハッシュ

9.5 server(サイト)ブロック

キー 型 / 値 既定値 説明
name 文字列 — Manager/コンバーターがファイル conf/vhost/{name}.toml を選ぶためだけに使用。サイトファイルには保存せず、読み込み時はファイル名が優先
domain 配列、完全一致/*.x/x.*/* [] "*" は既定サイト
listen ":80" または { addr, ssl, http2, http3 } 必須 リスナーとプロトコルスイッチ
root / index パス / 配列 空 / ["index.html"] サイトルートとインデックスファイル
default_type MIME — サイトレベルの MIME フォールバック
locations 配列 — ロケーション。§9.6 を参照
ssl オブジェクト — §9.13 を参照
error_page { "404" = "file:4xx.html" } http レベルを継承 ステータス → file:/root:/link: ターゲット
error_page_root ディレクトリ http/global を継承 相対 file: ターゲットのサイトレベルルート
access_log パス/オブジェクト http を継承 サイトのアクセスログ。{ enabled = false } で閉じる
waf オブジェクト グローバルを継承 サイトの WAF 上書き
http2 / http3 / ktls / sendfile / client_max_body_size bool / サイズ http を継承 サイトレベルの上書き
disabled_modules 配列 [] サイトで無効化するモジュール
schedule オブジェクト オフ 時間帯: timezone(IANA)、open[](days/start/end)、reason、status(400-599、既定 503)、page
strict_sni_host bool false Host が SNI と一致する必要(不一致は 421)
https_redirect bool false 平文から https へ 308
limit_rate / limit_rate_after サイズ 無制限 サイトのレート制限と無制限枠
disabled bool false 一時的にオフライン
rewrite 配列 [] rewrite ルール。cond で条件指定(§9.6)

9.6 location ブロック

path の構文: = /exact、/prefix/、^~ /static/(正規表現をスキップ)、 ~ /、~* / の正規表現、@name(内部専用)。優先順位は完全一致 > 最長前方 一致(^~ は正規表現をスキップ)> 順序どおりの正規表現 > 最長前方一致です。

キー 型 / 値 既定値 説明
type static/proxy/fastcgi/uwsgi/scgi/grpc/memcached/concat/image/nchan/upload/return/redirect/mp4/empty_gif/stub_status/外部 static コンテンツハンドラー
root / alias パス サイトを継承 alias はロケーションのプレフィックスを置き換え、DAV もこれに従う
index / autoindex 配列 / bool ["index.html"] / false インデックス(内部リダイレクト)/ ディレクトリ一覧
default_type / internal MIME / bool — / false MIME 上書き / 内部専用アクセス
try_files 配列 [] 順次プローブ。最後の項目は =code または内部 URI。$uri/ のみディレクトリに一致
disable_symlinks bool false docroot 下のいずれかのシンボリックリンクコンポーネント → 403
return { code, url | text } — ステータス/リダイレクト/テキスト
error_page / access_log サイトレベルと同じ 継承 上書き
client_max_body_size / limit_rate / limit_rate_after / sendfile 上記と同じ 継承 ロケーションレベルの上書き
waf オブジェクト 継承 ロケーションレベルの WAF スイッチ

rewrite(server/location): 無条件ルールは [pattern, replacement, flag] を 使用し、条件付きルールは cond を持つオブジェクトを使用します。cond は 1 つのテーブルまたは配列(AND)です。対象: path と exists/is_file/is_dir/is_exec のブール値、または var と eq/ne/matches/not_matches/truthy に任意の ignore_case を加えた もの。フラグ: last/break/redirect/permanent。flags = ["break"] は 書き換えて以降の rewrite ルールを停止し、break = true のルールは URI を 変更せずに停止します。? を含む置換は元のクエリを破棄します。http(s):// ターゲットは外部リダイレクトになります。内部リダイレクトが 10 回を超えると 500 になります。旧 if ブロックと条件付き return/set/break は削除 されました。

9.7 upstream

キー 型 / 値 既定値 説明
name 文字列 必須 プール名。proxy_pass = "http://name" で参照
lb round_robin/least_conn/ip_hash round_robin スケジューラー
servers [{ addr, weight, max_fails, fail_timeout_sec, down }] 必須 weight の既定は 0(1 として扱われる)
keepalive 整数 オフ アイドル接続プール
health_check { type=http|tcp, uri, interval_sec=5, timeout_sec=3, falls=2, rises=2, expected_min_status=200 } オフ アクティブヘルスチェック
sticky { cookie_name, path, expires_sec } オフ セッション永続化

実行時の変更: POST/PATCH/DELETE /api/upstreams/<name>/servers… (persist:true で書き戻し)。

9.8 stream と mail

stream(トップレベル、純粋なパススルー): upstreams[] (name/servers)、servers[]: listen(":port" または { addr, udp })、protocol(tcp/udp)、proxy_pass(プール/addr/ $ssl_preread_server_name)、return(proxy_pass とは排他)、ssl_preread (ClientHello から SNI を読み取る)、sni(ドメイン → { proxy_pass } ルーティング)、proxy_connect_timeout_sec(既定 5)。TLS 終端 / アクセス ログ / 接続数制限は実装されていません。

mail(トップレベル): servers[]: listen(必須)、proxy_pass (必須)、proxy_protocol(既定 false、アップストリームへ PROXY v1)、 timeout_sec(既定 60、I/O 時に更新)。name/protocol キーは現在無視 されます(プレーン TCP パススルー)。アップストリームの失敗は接続を閉じます。

9.9 waf ブロック

キー 型 / 値 既定値 説明
enabled bool false サイト/ロケーションの waf が上書き可能
engine full/fast full full = SecRule/CRS エンジン、fast = 軽量なシグネチャチェック(ルールコンパイルなし)
rules [{ id, name, pattern, is_regex, caseless, targets, action, comment }] [] targets: URI/ARGS/HEADERS/BODY/COOKIE/UA/REFERER/IP。action: block/allow/log。allow は CRS を短絡
response_rules 配列(block のみ) [] レスポンスボディ検査。ヒット → 403 + X-WAF-Blocked
response_body_limit バイト 1m レスポンス検査バッファの上限
ip_lists(別名 ip_blacklist/ip_whitelist) { white, black } 空 ホワイトリストは許可、ブラックリストは 403
cc { enabled, window_sec=60, max_requests=600, key=ip|ip+uri|ip+ua|$var, block_sec=60, log_interval_sec=30 } オフ CC 保護。ログ抑制ウィンドウ
crs bool false CRS をロード: ディスクの conf/waf/crs.toml を優先、なければ組み込み crs-lite
rules_files / rules_text TOML パス / SecRule テキスト — wxserver-convert -from crs による完全な CRS
paranoia_level / inbound_anomaly_threshold / outbound_anomaly_threshold 整数 1 / 5 / 4 CRS チューニング
rule_exclusions ID 配列 [] ID で CRS ルールを除外
skip_unsupported_rules bool false 未サポートのディレクティブをスキップ

カスタムルールは CRS より先に実行されます。サイトルール ID は 1000000+、 グローバルは 100000+。@rx ルールは共有 DFA キャッシュ (conf/waf/cache/、WXSERVER_WAF_CACHE=0 で無効)に事前コンパイルされます。

9.10 モジュールクイックリファレンス

キーはロケーション(または http/server レベル)に、あるいは modules.<name> の下に置きます。完全なセマンティクスは docs/options-reference.md を参照してください。

モジュール 主要キー(既定値) 備考
proxy proxy_pass(必須)、proxy_set_header、proxy_hide_header、proxy_intercept_errors、proxy_redirect、proxy_next_upstream{http_codes,timeout}、proxy_next_upstream_tries、proxy_buffering_off、proxy_connect/read_timeout_sec(5⁄60)、proxy_cache、proxy_cache_valid リバースプロキシ。Upgrade+Connection で WS トンネルを有効化。アップストリームの失敗 502⁄504 はエラーページを描画(error_page 優先、組み込み 5xx フォールバック)、詳細は error.log へ。ホスト名はマスターが定期的に解決し、ワーカーの接続失敗後に再取得
fastcgi fastcgi_pass(必須)、fastcgi_param(s)、fastcgi_params_file、fastcgi_index、fastcgi_split_path_info、fastcgi_hide_header、fastcgi_intercept_errors、fastcgi_keep_conn(false)、fastcgi_keep_conn_max(1)、fastcgi_keep_conn_idle_sec(15)、fastcgi_*_timeout_sec(5/60/60)、fastcgi_check_script(true) PHP。REQUEST_URI は常に元の URI。keepalive は既定でオフのため、アイドル接続が PHP-FPM の pm.max_children を枯渇させません。fastcgi_pass のホスト名はマスターが 5 分ごとに解決して shared_state にキャッシュ(Unix ソケットは DNS をバイパス)
uwsgi/scgi <p>_pass(必須)、<p>_param、<p>_params_file、<p>_connect/read_timeout_sec(5⁄60)、modifier1(0) UWSGI/SCGI プロトコル。ホスト名はマスターが解決してキャッシュ
grpc grpc_pass(必須)、grpc_tls、grpc_tls_server_name/ca/client_cert/client_key、grpc_*_timeout_sec(5⁄60)、grpc_intercept_errors h2 パススルー。grpc-status はトレーラー経由。ホスト名はマスターが解決してキャッシュ(TLS SNI はホスト名を保持)
memcached memcached_pass(必須)、memcached_key($host$request_uri)、memcached_content_type、タイムアウト(5⁄10) GET/HEAD のみ。ミス → 404。ホスト名はマスターが解決してキャッシュ。Unix ソケットは未サポート
staticfile root/alias/index/autoindex/try_files/disable_symlinks、gzip_static/brotli_static/zstd_static、dav{methods,create_full_put_path} WebDAV RFC 4918。事前圧縮 br>zstd>gzip
rewrite rewrite[[pat,repl,flag]]、オブジェクト + cond、set、return flag の既定は last
limit limit_req{rate,burst=0,key,status=503}、limit_conn{limit,key,status=503} shared_state は既定で有効。カウンターは初期状態でワーカー間で共有
access access{rules[{action,cidr}],default=deny} 設定されたレベルは親を置き換える
auth_basic auth_basic{realm,users_file,users} htpasswd 互換
auth_request auth_request{url,method=GET,timeout_ms=3000,allow_codes=[200],deny_codes=[401,403],copy_headers} 外部認証サブリクエスト
auth_jwt auth_jwt{alg=HS256,secret,key_file,jwks_uri,leeway_sec=30,claims,realm} HS256/RS256/ES256
secure_link secure_link{secret,md5_arg,expires_arg,require=true} MD5(base64url) 署名付き URL
referer referer{valid,invalid_status=403} ホットリンク防止
realip realip{from,header=X-Forwarded-For,mode=recursive} recursive は信頼済みプロキシを右から左へスキップ
userid / browser / geoip userid{name,path,expires,domain}、browser{modern,ancient,deny_ancient}、geoip{db,on} 変数 $uid/$modern_browser/$geoip_*
headers headers{expires,add_headers,add_headers_always,set_headers,more_set_headers,more_clear_headers,more_headers,clear_headers} add はそのレベルで置き換え。more_* は親を先に処理
security_headers security_headers{enabled,hsts,hsts_plaintext,csp,x_frame_options,referrer_policy,permissions_policy,nosniff} 既定でオフ。フィールドごとにマージ
gzip/gunzip gzip{on,level=6,min_length=20,types,vary=true,proxied=true,disable,no_compression_4xx}、gunzip{on} 200/403/404 のみ
brotli/zstd brotli{on,level=5,min_length=256}、zstd{on,level=3,min_length=256} 動的な優先順位 br>gzip>zstd
sub/addition/ssi/charset/minify sub{patterns[{search,replace}],once,types}、addition{before,after,types}、ssi{on,types,limit=8m}、charset{charset,source_charset,override_charset,charset_types}、minify{on,types,max_size=256k} ボディ処理
image_thumb image_thumb{quality=75,cache,backend,types,default_mode,water{...},watermark_text} URL !c300x200.jpg
nchan nchan{channel,mode=pubsub,buffer=16,history,max_subscribers=1024,max_message=256k,poll_timeout_sec=30,heartbeat_sec=15,cors} SSE/WS/ロングポーリング
upload upload{dir=run/uploads,max_size=1g,cors} tus 1.0
mirror mirror{targets,copy_body=false} 非同期ミラー
accesslog/logsink access_log(オブジェクトは §9.11)、modules.http_logsink{protocol=udp,addr,url,format=json,timeout_ms=1000} リモートログシンク
error_guard modules.http_error_guard{enabled,window_sec=60,threshold=20,block_sec=300,status=429,count_codes,count_5xx,key,whitelist} エラー率ブロック
sysguard modules.http_sysguard{enabled,max_load1,min_mem_available_mb,status=503,retry_after=5} 過負荷保護

fastcgi はデフォルトで SCRIPT_FILENAME、QUERY_STRING、REQUEST_METHOD、HTTP_*、SERVER_ADDR、REMOTE_PORT、REDIRECT_STATUS などの変数を PHP に渡します。Host ヘッダのない HTTP/2・HTTP/3 リクエストでは HTTP_HOST を :authority から補完します。複数の Cookie ヘッダは "; " で結合します(結合しない場合、PHP は最初の cookie しか参照できず、WordPress のログインやセッションが壊れます)。

9.11 ログオブジェクト(error_log / access_log)

フィールド 型 / 値 既定値 説明
path $year/$month/$day 対応のパス 未設定(出力なし) ワークディレクトリからの相対。絶対ログディレクトリは logs/ を再マップ。off/- は拒否され、閉じるには enabled = false を使用
level debug/info/warn/error warn error_log のみ
enabled bool true false でこの階層の error_log/access_log を完全に閉じる(ファイル・stderr・sink のいずれにも出力しない)。下位層で再度有効化可能。クロスプラットフォームで /dev/null の代替
console bool false error_log のみ: stderr/journal にも書き込む。enabled = false が優先
max_size_mb / max_backups 整数 0 サイズローテーション / 保持コピー数
encrypt / key_file bool / パス false 行ごとに AES-256-GCM(WXE1:)。コンソールは読み取り時に復号
format text/binary text binary は .wxlog(wxserver-log で読み取り)
format_template テンプレート combined テキスト形式のみ
sample 整数 1 N リクエストにつき 1 行

9.12 manager.toml

キー 型 / 値 既定値 説明
enable bool false コンソールを有効化
listen host:port 127.0.0.1:9090 非ループバックには [tls] または allow_http=true が必要
tls 証明書ストアの { cert } または { cert_file, key_file } — コンソールの TLS
allow_cidr CIDR/裸の IP 配列 [] TCP ピアによる送信元ホワイトリスト。未一致は 403
trust_proxy / proxy_cidr bool / CIDR 配列 false / [] trust_proxy は空でない proxy_cidr が必要(フェイルクローズ)。X-Forwarded-*/Via/Forwarded を伴うリクエストは既定で拒否(403)
domain ホスト名 [] Host 検証、不一致は 421
allow_http bool false 非ループバックの平文を明示的に許可
users [{ name, password_hash }] 初回起動時に admin を作成 bcrypt
jwt { secret_file=run/jwt.secret, expire_sec=86400 } — セッショントークン
login { max_fail, window_sec, block_sec, captcha_after, captcha_ttl } — ログインロックアウトと CAPTCHA
totp システムが維持 — 2FA 状態は run/manager-totp.json(0600)。手動編集しない

9.13 acme.toml と ssl

[certs.<name>]: domains(必須)、email、challenge(auto/http/dns)、 directory/staging、timeout_sec=60、auto_renew=true、 renew_before_days=30、check_interval_hours=12、key_type=ec256、 eab_kid/eab_hmac_key、must_staple、preferred_chain、on_demand、 request_timeout_sec=30(1-180)、 dns{provider=cloudflare|alidns|tencentcloud|route53, credentials, api_base, ttl_sec=120, propagation_timeout_sec=120, propagation_delay_sec, resolvers, proxy}。

サイト ssl: cert(ストア名)または cert_file/key_file、protocols (TLS1.2⁄1.3)、ciphers、session_cache、client_cert_file/verify_client/ verify_depth(mTLS)、prefer_server_ciphers。

9.14 変数

内蔵: $uri $document_uri $request_uri $args $query_string $host $server_name $http_host $http_<header> $scheme $https $server_port $request_method $server_protocol $remote_addr $client_ip $binary_remote_addr $remote_user $document_root $content_length $content_type $is_args $internal_redirect、および $arg_*、$cookie_*。 モジュール登録: $jwt_claim_*/$jwt_error、$secure_link/ $secure_link_expires、$uid、$modern_browser/$ancient_browser、 $geoip_*、rewrite set と map/geo/split_clients の派生変数。解決順: 内蔵 → モジュール → 派生。

9.15 CLI と変換

wxserver -c <config>            # フォアグラウンドで起動
wxserver -t -c <config>         # 検証
wxserver -s reload|stop|quit    # シグナル制御
wxserver -no-manager            # コンソールを無効化
wxserver --service install|uninstall|start|stop|restart|status
wxserver --reset-password [pwd] / --reset-totp
wxserver-convert -from auto|nginx|apache|htaccess|crs -in <file> [-out <file>] [--split-vhosts conf/vhost]
wxserver-tool htpasswd / bench / precompress / toml

wxserver-convert はファイルモードで include を展開します。--split-vhosts はサイトごとに conf/vhost/{name}.toml を書き込みます。.htaccess は自動 判定され、貼り付け可能な location フラグメントを生成します。未サポートの ディレクティブは警告を出力します(-quiet で抑制)。ツールの詳細は第 7 章を 参照してください。

← Previous Article 第8章 — モジュール Next Article → 第10章 — トラブルシューティング

Comments

No comments yet