2

My Scenario:

i have running apache severing my UI and i have my node api running on port 2000 and i have a reserves proxy on apache to proxy request to api and i have configure ssl as well and i want to redirect http to https. this is my following config

<VirtualHost *:80>

        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html


        RewriteEngine on
        RewriteRule ^/api/v1/(.*) http://localhost:2000/api/v1/$1 [P,L]

        RewriteEngine on
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

SSL config

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/example.com/public_html     

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined    

        SSLEngine on 

        SSLCertificateFile  /etc/apache2/ssl/example.com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/pkey.key    

        <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
        </FilesMatch>
        <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
        </Directory>


    </VirtualHost>
</IfModule>

i'm getting too many redirects, how can i solve this?

3
  • 2
    Can you view the redirects using the network debug tab in chrome, etc, and see what the redirects are looping through? Jul 12, 2018 at 16:08
  • Also, given that I answered your other question about the reverse proxy for port 2000 /api/v1 reuqests, you probably want that in your SSL vhost block, not your port 80 vhost. your port 80 vhost should just redirect everything to https:// and then your https:// vhost does the reverse proxy to your node app. Jul 12, 2018 at 16:09
  • cool. i used .htaccess to redirect http to https then it got sorted. il move api block to ssl and check.
    – Frodo
    Jul 13, 2018 at 6:30

1 Answer 1

3

You could just use a redirect instead of rewrite rules:

<VirtualHost *:80> 
ServerAdmin [email protected]    
ServerName example.com 

ServerAlias www.example.com 

Redirect permanent / https://www.example.com

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 


</VirtualHost>

Not the answer you're looking for? Browse other questions tagged .