Force all HTTP requests to HTTPS (Apache)
-
The Configuring nginx as a proxy article provides nginx config to use SSL. Is there anything like this available for Apache? My aim is to force all HTTP requests to HTTPS.
-
-
@pichalite Thanks for the link, but can you confirm if it works for you? It doesn't work for me. This is my example.com.conf file in sites-enabled:
ProxyRequests off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /socket.io/1/websocket ws://127.0.0.1:4567/socket.io/1/websocket ProxyPassReverse /socket.io/1/websocket ws://127.0.0.1:4567/socket.io/1/websocket ProxyPass /socket.io/ http://127.0.0.1:4567/socket.io/ ProxyPassReverse /socket.io/ http://127.0.0.1:4567/socket.io/ ProxyPass / http://127.0.0.1:4567/ ProxyPassReverse / http://127.0.0.1:4567/ <VirtualHost *:80> ServerName example.com DocumentRoot /usr/local/apache2/htdocs Redirect permanent / https://example.com </VirtualHost> <VirtualHost *:443> SSLEngine on SSLProtocol all -SSLv2 SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM SSLCertificateFile /etc/apache2/ssl/ssl.crt SSLCertificateKeyFile /etc/apache2/ssl/private.key SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem </VirtualHost>
-
@henrywright I use nginx for proxy. I don't think the virtualhost method works here.
Try this...
-
@pichalite Thanks, I'll give that a try. Which directory should I put my .htaccess file in? I'm not familiar with the NodeBB file structure.
-
Hey,
You can replace your VHost on port 80 to this.
<VirtualHost *:80> ServerName example.com DocumentRoot /usr/local/apache2/htdocs RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </VirtualHost>
It will look at your URL if there is no HTTPS and convert the URL to HTTPS.
-
@hoathenguyen85 Hey! I've tried virtual host rewrite rules such as this and they don't work. Can you confirm if this works for you?