Home  >  Article  >  Web Front-end  >  Detailed practical explanation of enabling HTTPS in Node.js

Detailed practical explanation of enabling HTTPS in Node.js

高洛峰
高洛峰Original
2016-12-09 09:58:111501browse

1. First, go to Tencent Cloud to apply

Detailed practical explanation of enabling HTTPS in Node.js

After the application is successful, you can directly download the certificate and use it.

Detailed practical explanation of enabling HTTPS in Node.js

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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn