I have a GoDaddy VPS managed server. I’ve installed Node/NPM, SSL certs, etc. successfully, but running into a couple issues with .htaccess. I can force http to https with the following code in .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I can also bypass having to do an Apache reverse proxy so that the server/domain is using NodeJS instead of Apache by adding the following to .htaccess:
RewriteEngine on
RewriteRule (.*) http://localhost:3000/$1 [P,L]
The issue I’m having is getting both to work at the same time. Force SSL AND point to NodeJS for the server.
I’m not sure if .htaccess is the best route to go for both goals.
2
Answers
You should not use .htaccess at all if you have access to Apache configuration files (detailed explanation here).
In your http (:80) Virtual host configuration you can put your https forcing rules, and in your https (:443) Virtual host you can put your reverse proxy rules. Also, using
ProxyPass
directive instead ofRewriteRule
with[P]
flag might give some performance benefit:If you have access to Apache .conf files, try to create virtual host with following code:
Then enable just created apache virtual host and don’t forget install all required sub modules:
If you need to create a new apache
.conf
file, please follow this few steps:Navigate to apache vhost default directory
/etc/apache2/sites-avaliable
and create new virtual host configuration file with example code.Enable this configuration file use linux symlink or use apache tool
a2ensite
.Restart or reload apache service.
Example:
Put example configuration described top to this file.
Create symlink:
or
Finaly reload new configuration by restarting apache service:
The best way to manage/create web host ssl certificates is use
Let’s Encrypt
service. Please follow guide hereIf you have already valid certificate, you can of course convert it to pem format by folowing this gude.
For addition information how to configure Apache service on Centos OS please read guide How To Set Up Apache Virtual Hosts on CentOS 6