Issue
I have a NextJS server running on aws ec2 ubuntu instance port 3000 and want to redirect traffic from port 443 with Apache to port with NextJS app. I achieved the desired result, but it works only in the Chrome browser.
That's how my Apache config file looks like:
<VirtualHost *:443>
ServerName domain.com
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
SSLEngine on
SSLCertificateFile /etc/ssl/certs/www_domain_com.crt
SSLCertificateKeyFile /etc/ssl/private/domain_private.key
SSLCertificateChainFile /etc/ssl/certs/www_domain_com.ca-bundle
</VirtualHost>
These are my last logs from apache:
[Thu Jan 25 20:11:21.975521 2024] [mpm_event:notice] [pid 2267:tid 140152490424192] AH00492: caught SIGWINCH, shutting down gracefully
[Thu Jan 25 20:11:22.062393 2024] [mpm_event:notice] [pid 2367:tid 139778842716032] AH00489: Apache/2.4.52 (Ubuntu) OpenSSL/3.0.2 configured -- resuming normal operations
[Thu Jan 25 20:11:22.062521 2024] [core:notice] [pid 2367:tid 139778842716032] AH00094: Command line: '/usr/sbin/apache2'
When I try to open the domain.com in Chrome it works fine, but any other browser cannot get the response back and waits until ttl expires.
Solution
The answer was pretty simple....Other browsers except Chrome by default try to send the request for the example.com to port 80. Therefore I should have been redirecting the traffic from port 80 to 443.
Here is my full configuration file:
<VirtualHost *:80>
Redirect "/" "https://example.com/"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ProxyPreserveHost On
ProxyPass "/" "http://localhost:3000/"
ProxyPassReverse "/" "http://localhost:3000/"
SSLEngine on
SSLCertificateFile /etc/ssl/certs/www_example_com.crt
SSLCertificateKeyFile /etc/ssl/private/example_private.key
SSLCertificateChainFile /etc/ssl/certs/www_example_com.ca-bundle
</VirtualHost>
Answered By - nikita_trifan Answer Checked By - Marie Seifert (WPSolving Admin)