0

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>

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.