If you have access to Apache .conf files, try to create virtual host with following code:
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
SSLEngine on
SSLCertificateFile /etc/path/to/fullchain.pem
SSLCertificateKeyFile /etc/path/to/privkey.pem
ProxyRequests off
SSLProxyEngine on
ErrorLog /var/log/nodejs/errorLog443.log
TransferLog /var/log/nodejs/transferLog443.log
<Location />
ProxyPass http://localhost:3000/
Order deny,allow
Deny from all
Allow from all
</Location>
</VirtualHost>
Then enable just created apache virtual host and don't forget install all required sub modules:
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2ensite example.apache.host.conf
sudo service apache2 restart
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:
cd /etc/apache2/sites-avaliable
vim new-virtual-host.conf
Put example configuration described top to this file.
Create symlink:
cd /etc/apache2/sites-enabled/
ln -s ../sites-available/new-virtual-host.conf new-virtual-host.conf
or
sudo a2ensite new-virtual-host.conf
Finaly reload new configuration by restarting apache service:
sudo service apache2 restart
The best way to manage/create web host ssl certificates is use Let’s Encrypt
service. Please follow guide here
If you have already valid certificate, you can of course convert it to pem format by folowing this gude.
Updated for Centos OS:
For Centos OS just open apache2 config file at location
/etc/httpd/conf/httpd.conf
, scroll down to the very bottom of the
document to the section called Virtual Hosts. There you can edit/add
virtual host section with appropirate configuration you need.
For addition information how to configure Apache service on Centos OS please read guide How To Set Up Apache Virtual Hosts on CentOS 6