I'm trying to make a Node.js + Express + Vue.js + Apache + MySQL application work on my server via HTTPS protocol. (works fine locally or via HTTP on the server).
There is a URL (subdomain) for API which returns a JSON result, let's say "api.mysite.com".
I tried different approaches, right now I use port 443 in my app.js (it doesn't help):
const PORT = process.env.PORT || 443
app.listen(PORT, () => {
console.log(`Server stated on port ${PORT}`)
})
On my local machine I use port 5000 and access the app by "http://locahost:5000" (and it works fine).
"/etc/apache2/sites-available/my-site-api.conf":
<VirtualHost *:80>
ServerName api.mysite.com
ServerAlias api.mysite.com
DocumentRoot /var/www/mysite/api
RewriteEngine on
RewriteCond %{SERVER_NAME} =api.mysite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
"/etc/apache2/sites-available/my-site-api-le-ssl.conf":
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName api.mysite.com
ServerAlias api.mysite.com
DocumentRoot /var/www/mysite/api
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =api.mysite.com [OR]
# RewriteCond %{SERVER_NAME} =api.mysite.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/api.mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/api.mysite.com/privkey.pem
</VirtualHost>
</IfModule>
Let me know if you need any other info.
Thanks a lot in advance!