Add log-stderr, keep-conn, and path_info presets to FastCGI plugin
This commit is contained in:
parent
3dfc570d57
commit
52558e9277
3 changed files with 143 additions and 5 deletions
|
|
@ -51,12 +51,23 @@ from plugins import PluginContext, PluginInterface, PluginResult, PluginType
|
|||
class FastcgiPlugin(PluginInterface):
|
||||
"""Plugin to configure FastCGI parameters for PHP-FPM"""
|
||||
|
||||
# Built-in path-info regex presets
|
||||
PATH_INFO_PRESETS = {
|
||||
"php": r"^(/.+\.php)(/.*)?$",
|
||||
"python": r"^(/.+\.py)(/.*)?$",
|
||||
"perl": r"^(/.+\.(?:pl|cgi))(/.*)?$",
|
||||
"ruby": r"^(/.+\.rb)(/.*)?$",
|
||||
"any": r"^(.+?)(/.*)?$",
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.enabled = True
|
||||
self.document_root = "/var/www/html"
|
||||
self.script_filename = "%[path]"
|
||||
self.index_file = "index.php"
|
||||
self.path_info = True
|
||||
self.path_info = "php" # False | preset name | custom regex string
|
||||
self.log_stderr = False
|
||||
self.keep_conn = True
|
||||
self.custom_params = {}
|
||||
self.pass_headers = [] # list of {"name": str, "condition": str|None}
|
||||
|
||||
|
|
@ -80,6 +91,16 @@ class FastcgiPlugin(PluginInterface):
|
|||
- index_file: Default index file
|
||||
- path_info: Enable PATH_INFO support
|
||||
- custom_params: Dictionary of custom FastCGI parameters
|
||||
- path_info: Enable PATH_INFO splitting. Accepts:
|
||||
- False / "false" / "no" / "0": disabled
|
||||
- "php" (default): ^(/.+[.]php)(/.*)?$
|
||||
- "python": ^(/.+[.]py)(/.*)?$
|
||||
- "perl": ^(/.+[.](pl|cgi))(/.*)?$
|
||||
- "ruby": ^(/.+[.]rb)(/.*)?$
|
||||
- "any": ^(.+?)(/.*)?$
|
||||
- any other string: used as-is as the regex
|
||||
- log_stderr: Forward FastCGI app's stderr to HAProxy logs (default: false)
|
||||
- keep_conn: Reuse FastCGI connections between requests (default: true)
|
||||
- pass_headers: Headers to forward to the FastCGI application.
|
||||
HAProxy omits Authorization, Proxy-Authorization, and hop-by-hop headers
|
||||
by default — this directive is required to pass them through.
|
||||
|
|
@ -107,7 +128,19 @@ class FastcgiPlugin(PluginInterface):
|
|||
self.index_file = config["index_file"]
|
||||
|
||||
if "path_info" in config:
|
||||
self.path_info = str(config["path_info"]).lower() in ["true", "1", "yes"]
|
||||
val = str(config["path_info"]).lower()
|
||||
if val in ["false", "0", "no"]:
|
||||
self.path_info = False
|
||||
elif val in ["true", "1", "yes"]:
|
||||
self.path_info = "php" # backward-compatible: true → php preset
|
||||
else:
|
||||
self.path_info = str(config["path_info"]) # preset name or custom regex
|
||||
|
||||
if "log_stderr" in config:
|
||||
self.log_stderr = str(config["log_stderr"]).lower() in ["true", "1", "yes"]
|
||||
|
||||
if "keep_conn" in config:
|
||||
self.keep_conn = str(config["keep_conn"]).lower() in ["true", "1", "yes"]
|
||||
|
||||
if "custom_params" in config:
|
||||
self.custom_params = config["custom_params"]
|
||||
|
|
@ -155,9 +188,16 @@ class FastcgiPlugin(PluginInterface):
|
|||
fcgi_app_lines.append(f" docroot {self.document_root}")
|
||||
fcgi_app_lines.append(f" index {self.index_file}")
|
||||
|
||||
if self.log_stderr:
|
||||
fcgi_app_lines.append(" log-stderr")
|
||||
|
||||
if self.keep_conn:
|
||||
fcgi_app_lines.append(" option keep-conn")
|
||||
|
||||
# PATH_INFO support
|
||||
if self.path_info:
|
||||
fcgi_app_lines.append(" path-info ^(/.+\\.php)(/.*)?$")
|
||||
regex = self.PATH_INFO_PRESETS.get(self.path_info, self.path_info)
|
||||
fcgi_app_lines.append(f" path-info {regex}")
|
||||
|
||||
# Set SCRIPT_FILENAME if customized
|
||||
if self.script_filename and self.script_filename != "%[path]":
|
||||
|
|
@ -184,6 +224,8 @@ class FastcgiPlugin(PluginInterface):
|
|||
"document_root": self.document_root,
|
||||
"index_file": self.index_file,
|
||||
"path_info": self.path_info,
|
||||
"log_stderr": self.log_stderr,
|
||||
"keep_conn": self.keep_conn,
|
||||
"custom_params_count": len(self.custom_params),
|
||||
"pass_headers_count": len(self.pass_headers)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue