'Apache HTTPS Reverse Proxy URL Redirection

I've a node application running on 3001 port. For HTTP to HTTPS, I've configured apache virtual host with reverse proxy and it is working fine. Now I need to redirect http://nodeapp.mydomain.com to https://nodeapp.mydomain.com and http://nodeapp.mydomain.com:3001 to https://nodeapp.mydomain.com and http://100.100.100.100:3001 to https://nodeapp.mydomain.com Can anyone please help me how to achieve it using virtual host configuration instead of writing a .htaccess file?

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName nodeapp.mydomain.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://100.100.100.100:3001/
    ProxyPassReverse / http://100.100.100.100:3001/
    ErrorLog "/var/log/httpd/mydomain.com-error_log"
    CustomLog "/var/log/httpd/mydomain.com-access_log" common
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/nodeapp_mydomain_com.crt
    SSLCertificateKeyFile /etc/pki/tls/certs/nodeapp_mydomain_com.key
</VirtualHost>


Solution 1:[1]

To redirect http://nodeapp.mydomain.com to https://nodeapp.mydomain.com, add these lines to the virtual host configuration:

<VirtualHost *:80>
    ServerName nodeapp.mydomain.com
    Redirect Permanent / https://nodeapp.mydomain.com/
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =nodeapp.mydomain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

You can copy paste the same code to the conf file, and modify the corresponding domains/subdomains there.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SJaafar