Fixing Apache ‘ssl_error_rx_record_too_long’ on Alpine Linux (SSL Port 443 Mismatch)
Resolve the 'ssl_error_rx_record_too_long' error on Alpine Linux Apache servers, ensuring correct SSL configuration for HTTPS on port 443.
Resolve the 'ssl_error_rx_record_too_long' error on Alpine Linux Apache servers, ensuring correct SSL configuration for HTTPS on port 443.
Introduction
Encountering "ssl_error_rx_record_too_long" in your browser when trying to access an Apache web server configured for HTTPS can be a frustrating experience. This error typically indicates that your browser, expecting a secure SSL/TLS handshake on port 443, instead received plain unencrypted HTTP data, or malformed SSL data, leading to a protocol mismatch. On Alpine Linux, with its lean and secure defaults, this issue often stems from subtle misconfigurations in Apache's SSL setup, preventing the mod_ssl module from properly encrypting traffic on the designated HTTPS port.
This guide will walk you through diagnosing and resolving this common issue on an Alpine Linux Apache server, ensuring your site serves content securely over HTTPS.
Symptom & Error Signature
When experiencing this issue, users will typically see an error page in their web browser, often accompanied by a specific error code.
Browser Error Examples:
- Firefox: "SSL_ERROR_RX_RECORD_TOO_LONG"
- Chrome/Edge: "ERR_SSL_PROTOCOL_ERROR" or "This site can't provide a secure connection"
Apache Access/Error Log Entries (less common for this specific error, but worth checking):
While ssl_error_rx_record_too_long is primarily a client-side (browser) error indicating a problem with the server's initial response, Apache's error_log might show related issues if mod_ssl fails to initialize or encounters certificate problems.
[timestamp] [error] [pid XXXXX:tid XXXXX] (X)Permission denied: [client IP:port] AH00088: Unable to access the SSL_CTX_set_session_id_context shared memory semaphore
[timestamp] [error] [pid XXXXX:tid XXXXX] SSL Library Error: error:140A80B1:SSL routines:SSL_CTX_new:system lib
The above log entries are less frequent but can point to underlying issues with SSL initialization or file permissions, which indirectly lead to the browser error. The primary indicator for this specific problem is the browser error itself.
Root Cause Analysis
The core reason behind the ssl_error_rx_record_too_long error on port 443 is that the web server (Apache) is sending non-SSL (plain HTTP) data when the client (browser) expects SSL/TLS encrypted data. For Alpine Linux Apache specifically, this usually boils down to one or more of the following:
mod_sslNot Enabled or Loaded: Apache's SSL capabilities are provided by themod_sslmodule. If this module is not enabled or fails to load correctly, Apache will not be able to perform SSL handshakes, and any traffic directed to port 443 will be treated as plain HTTP.- Incorrect
VirtualHostConfiguration:- A
VirtualHostblock configured for plain HTTP (e.g., missingSSLEngine On) is accidentally listening on port 443. - The
VirtualHost *:443block is present but lacksSSLEngine Onor has incorrectSSLCertificateFile/SSLCertificateKeyFiledirectives. - An HTTP
VirtualHost(port 80) is inadvertently configured withListen 443, overriding the SSL configuration.
- A
- Conflicting
ListenDirectives: MultipleListendirectives for port 443, or aListen 443directive placed within a non-SSLVirtualHostblock, can cause ambiguity or incorrect protocol binding. - Incorrect Certificate/Key Paths or Permissions: If Apache cannot read the specified SSL certificate (
.crt) or private key (.key) files due to incorrect paths or file permissions,mod_sslwill fail to initialize, resulting in plaintext responses. - Another Service on Port 443: Less common but possible: another application is already bound to port 443, preventing Apache from listening correctly. This usually manifests as Apache failing to start, but could lead to unexpected behavior if it's a proxy that misbehaves.
Step-by-Step Resolution
Follow these steps to diagnose and resolve the "ssl_error_rx_record_too_long" issue on your Alpine Linux Apache server.
1. Verify Apache Status and mod_ssl Module
First, ensure Apache is running and that the mod_ssl module is loaded.
Check Apache Service Status:
sudo rc-service apache2 statusYou should see output indicating
apache2isstarted. If not, try to start it and check logs for errors:sudo rc-service apache2 start sudo tail -f /var/log/apache2/error_logConfirm
mod_sslis Enabled and Loaded: On Alpine, Apache modules are typically enabled by ensuring their configuration file exists inconf.dand is included.mod_sslis usually enabled via/etc/apache2/conf.d/ssl.confor a similar include.First, check if
mod_sslis compiled and available:apache2 -M | grep ssl_moduleIf you don't see
ssl_module (shared), you might need to install it. Alpine'sapache2package usually includesmod_ssl, but ensure you have theapache2-sslpackage if it's separated in your version.sudo apk add apache2-ssl # if not already installedNext, ensure the module is explicitly loaded in your
httpd.conf. Look for lines similar to this:# In /etc/apache2/httpd.conf or a file in /etc/apache2/conf.d/ LoadModule ssl_module modules/mod_ssl.soAlso, confirm that the SSL configuration file is included. This is typically where
mod_ssldirectives reside.# In /etc/apache2/httpd.conf Include conf.d/ssl.confMake sure
/etc/apache2/conf.d/ssl.confexists and contains basic SSL directives.
2. Inspect Apache Configuration Files for Port 443
The most common cause is an incorrect configuration around the Listen 443 directive and the corresponding VirtualHost block.
Locate Configuration Files: Main Apache config:
/etc/apache2/httpd.confSSL-specific config:/etc/apache2/conf.d/ssl.conf(or a similar name) VirtualHost configs:/etc/apache2/conf.d/vhosts.confor individual files in/etc/apache2/conf.d/vhosts/Verify
Listen 443: Ensure Apache is listening on port 443. Checkhttpd.confand any included files. There should be only oneListen 443directive.# In /etc/apache2/httpd.conf or conf.d/ssl.conf Listen 443 httpsAvoid having
Listen 443inside a<VirtualHost>block unless you explicitly know why and how to correctly configure it. Typically,Listendirectives are global.Review
VirtualHost *:443Configuration: This is critical. Find your HTTPSVirtualHostblock for port 443.# In /etc/apache2/conf.d/ssl.conf or a dedicated vhost file <VirtualHost *:443> ServerName your-domain.com DocumentRoot /var/www/your-domain SSLEngine On SSLCertificateFile "/etc/ssl/your-domain/your-domain.crt" SSLCertificateKeyFile "/etc/ssl/your-domain/your-domain.key" SSLCACertificateFile "/etc/ssl/your-domain/chain.pem" # Optional, but recommended for full chain # Other SSL options (protocols, ciphers, headers) SSLProtocol All -SSLv2 -SSLv3 SSLCipherSuite HIGH:!aNULL:!MD5 Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Content-Type-Options "nosniff" Header always set X-XSS-Protection "1; mode=block" Header always set X-Frame-Options "DENY" # ... other directives for your site (Log files, Directory, etc.) </VirtualHost>SSLEngine On: This directive MUST be present within theVirtualHost *:443block. If it's missing orSSLEngine Off, Apache will serve plain HTTP on port 443.SSLCertificateFile&SSLCertificateKeyFile: Verify the paths are absolutely correct and point to your actual certificate and private key files.SSLCACertificateFile: While optional, it's good practice to include your certificate authority (CA) bundle for better browser compatibility.
3. Check Certificate and Key File Permissions
Incorrect permissions on your SSL certificate and key files can prevent Apache from reading them, leading to SSL initialization failure.
Verify File Paths and Ownership: Navigate to the directories where your certificate and key files are stored (e.g.,
/etc/ssl/your-domain/).ls -l /etc/ssl/your-domain/Adjust Permissions:
- The private key file (
.key) should be readable only by the root user or the user Apache runs as, and no one else.sudo chmod 600 /etc/ssl/your-domain/your-domain.key sudo chown root:root /etc/ssl/your-domain/your-domain.key - The certificate file (
.crt) and chain file (.pem) can be world-readable, but it's often safer to restrict them to root as well.sudo chmod 644 /etc/ssl/your-domain/your-domain.crt sudo chmod 644 /etc/ssl/your-domain/chain.pem sudo chown root:root /etc/ssl/your-domain/your-domain.crt sudo chown root:root /etc/ssl/your-domain/chain.pem
- The private key file (
4. Test Apache Configuration Syntax
Before restarting Apache, always test your configuration for syntax errors.
sudo apache2ctl configtest
You should see Syntax OK. If there are errors, Apache will point to the problematic line and file. Correct any errors before proceeding.
5. Restart Apache Service
After making changes, restart Apache for them to take effect.
sudo rc-service apache2 restart
6. Verify Port Listening and Connectivity
Check if Port 443 is Open: Use
netstatorssto confirm Apache is listening on port 443.sudo netstat -tulnp | grep 443 # Or for ss sudo ss -tulnp | grep 443You should see an entry like
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN PID/apache2Test SSL Connection with
openssl: You can simulate an SSL handshake from the server itself.openssl s_client -connect localhost:443If successful, you'll see a lot of SSL/TLS certificate information, the handshake details, and eventually
Verify return code: 0 (ok). If you see errors likeerror:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol, it still indicates a protocol mismatch, suggesting a deeper configuration issue.Check Firewall Rules (if applicable): If
netstatshows Apache listening on 443, but you still can't connect from an external machine, check your firewall (e.g.,ufw,iptables).For
iptableson Alpine (often manual or viaiptables-persistent):sudo iptables -L -nEnsure there's a rule allowing incoming TCP traffic on port 443. If not, add one:
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT # Remember to save iptables rules if they are not persistent by default
After completing these steps, try accessing your website again via HTTPS in your web browser. The ssl_error_rx_record_too_long error should now be resolved, and your site should load securely.
Our Production Verification Guarantee
Encountering a bug not covered here or running a non-standard kernel configuration? Our solutions are continually refined against real production incidents. Submit an environment trace for our editorial team to replicate.