Home >Web Front-end >JS Tutorial >Detailed practical explanation of enabling HTTPS in Node.js
1. First, go to Tencent Cloud to apply
After the application is successful, you can directly download the certificate and use it.
2. Configure nginx
Add your domain name configuration under /etc/nginx/conf.d/ such as xxx.com.conf, the content is as follows
server { listen 80; listen 443 ssl; server_name www.xxx.com; ssl_certificate /etc/nginx/ssl/www.xxx.com_cert.crt; ssl_certificate_key /etc/nginx/ssl/www.xxx.com.key; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:8360; } }
proxy_pass is the reverse proxy to The address of your node service.
sslcertificate and sslcertificate_key need to specify the certificate directory file, that is, copy the file you downloaded to the /etc/nginx/ssl directory.
3. Finally, just restart nginx. It's very simple.
Note The trouble comes when switching to https. https does not allow loading requests for http resources, so it is best to replace those addresses to support https.