keepalive
Read or set Apache's
KeepAlivedirective and reload the web server
- Command:
/go/keepalive - Category: Web server
- Required arguments: None. With no argument it sets
KeepAlive On. - Optional argument:
On,Off, orreturn - Output: A confirmation line, or the current value with
return - Last updated: 2026-11-19
On this page: Overview · Quick start · Syntax · Arguments · Output · Examples · Troubleshooting · Details · See also
Overview
/go/keepalive changes the Apache setting KeepAlive in Apache's main configuration file. KeepAlive decides whether a visitor's browser can send several requests over one connection (On) or must open a new connection for every request (Off).
Onis faster for visitors, because connections are reused. It is Apache's default.Offcan save memory on busy servers with many idle connections, but pages load more slowly.
After changing the file, the command reloads PHP-FPM and the web server.
The file it edits depends on the system:
| System | File |
|---|---|
| AlmaLinux, Rocky, CentOS, Red Hat, Fedora | /etc/httpd/conf/httpd.conf |
| Debian, Ubuntu | /etc/apache2/apache2.conf |
The setting applies to the whole server. It has no effect on Nginx.
Quick start
# Check the current value
/go/keepalive return
# Turn it off
/go/keepalive Off
# Turn it on
/go/keepalive On
Syntax
/go/keepalive [On|Off]
/go/keepalive return
| Form | Behavior |
|---|---|
/go/keepalive |
Sets KeepAlive On and reloads. |
/go/keepalive <value> |
Sets KeepAlive <value> and reloads. |
/go/keepalive return |
Prints the current value, then exits with code 1. |
/go/keepalive --noreload |
Meant to set On without reloading. The reload still happens. See Notes for maintainers. |
[!WARNING] The value is not checked, and every argument you pass becomes part of the value.
/go/keepalive Off --noreloadwritesKeepAlive Off --noreload, which makes the Apache configuration invalid. Apache accepts onlyOnorOff.
Arguments
| Argument | Required | Default | Notes |
|---|---|---|---|
[value] |
No | On |
Use On or Off. All arguments are joined with spaces. |
return |
No | — | Prints the current value. Not case-sensitive. |
--noreload |
No | — | Only recognized as the sole argument, and currently has no effect on the reload. |
The command has no other options.
Output
| Outcome | What you get |
|---|---|
return |
The current value, such as On. Empty if it can't be read. Exit code 1. |
| Value set | KeepAlive updated successfully., then the output of reload. |
The confirmation line is printed even when the file wasn't changed.
Logging
Every run is appended to /var/log/go/keepalive.log.
Examples
# Read the current value
/go/keepalive return
# Turn persistent connections off
/go/keepalive Off
# Turn them on again
/go/keepalive On
# Check the line in the configuration file (Debian and Ubuntu)
grep -n "KeepAlive" /etc/apache2/apache2.conf
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Apache doesn't reload, with an error such as KeepAlive must be On or Off |
An invalid value was written, for example Off --noreload. |
Fix the KeepAlive line in the file so it says On or Off, check it with apachectl configtest, then run reload. |
--noreload did not stop the reload |
The check for the flag has a typo. | Expected for now. See Notes for maintainers. |
return prints an empty line |
The file has no KeepAlive line (Apache then uses On), or the line is indented or uses a tab. |
Check the file by hand. |
| No effect on a server that uses Nginx | The setting is for Apache only. | Change Nginx's keepalive_timeout instead. |
| The command waits without printing anything | The operating system isn't supported, so the file name is empty and grep waits for input. |
Press Ctrl+C. |
Permission denied when adding the line |
The command wasn't run as root. |
Run it as root. |
Pages load slower after Off |
Each request needs a new connection. | Set it back to On, and lower keepalivetimeout instead. |
Details
What it does
- Logs the call, and finds Apache's main configuration file for the operating system.
- Reads the value from the first line that contains
KeepAlivefollowed by a space. - For
return: prints the value and stops. - Chooses the new value:
Onif there is no argument or the only argument is--noreload, otherwise all arguments joined together. - If the file has an active
KeepAliveline, replaces the value on every such line. Otherwise addsKeepAlive <value>to the end of the file. - Prints
KeepAlive updated successfully. - Reloads PHP-FPM and the web server with
reload. This step is always run.
flowchart TD
A["keepalive value"] --> B["Find Apache config file"]
B --> C{"return?"}
C -- "Yes" --> D["Print current value, exit 1"]
C -- "No" --> E["Set value: On if none, else the arguments"]
E --> F{"KeepAlive line exists?"}
F -- "Yes" --> G["Replace its value"]
F -- "No" --> H["Append the line"]
G --> I["reload"]
H --> I
Notes for maintainers
| Issue | Why it matters | Suggested fix |
|---|---|---|
The check for --noreload tests the text "@" instead of "$@" |
The pattern never matches, so the reload always runs. | Test "$@", and parse the flag properly. |
--noreload is recognized only as the sole argument, and otherwise becomes part of the value |
Off --noreload writes an invalid line and can stop Apache from reloading. |
Remove flags from the arguments before building the value. |
The value is not validated, and goes straight into sed |
Anything other than On or Off breaks Apache's configuration, and characters such as / or & break the sed command. |
Accept only On and Off in any case, and run apachectl configtest before the reload. |
The value is read with cut -d' ' -f2 |
An indented line or one with a tab returns an empty value. | Use awk '$1=="KeepAlive" {print $2}'. |
| The read pattern is not anchored | Commented-out lines can be matched. | Use ^[[:space:]]*KeepAlive[[:space:]], as the write pattern does. |
| An unsupported operating system leaves the file name empty | grep then reads the terminal and hangs. |
Stop with a message when the system is unknown. |
The line is appended with >> without sudo, and there is no root check |
Fails when not run as root. |
Re-run through sudo at the top, like most other commands. |
| The command edits Apache's main file | Package upgrades can replace it. | Write a separate file in conf.d (RPM) or conf-available (Debian). |
The success message always prints, and return exits with 1 |
A run that changed nothing still looks successful, and return looks like a failure. |
Report what changed, and use exit 0. |
The same template is probably used by keepalivetimeout and maxkeepaliverequests |
The same problems can exist there. | Check them and fix all three together. |
See also
| Command | Description |
|---|---|
keepalivetimeout |
Read or set Apache's KeepAliveTimeout directive |
maxkeepaliverequests |
Read or set Apache's MaxKeepAliveRequests |
reload |
Reload PHP-FPM and the active web server |
web |
Restart or reload the active web server |
gzip |
Enable or disable gzip compression in the web server |
checkapache |
Validate the Apache configuration |
apache |
Convert a GoAdmio server from Nginx to Apache |