Remarque: j'ai exécuté ces commandes sur macOS. Linux devrait fonctionner de la même manière. Je ne garantis pas pour Windows.
Dans le dossier racine du projet, exécutez:
openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365
Maintenant, exécutez:
openssl rsa -in keytmp.pem -out key.pem
Vous devriez maintenant avoir les fichierscert.pem
etkey.pem
dans le dossier.
Avec Express / Node.js, vous pouvez charger le certificat et la clé à l'aide de ce code:
const fs = require('fs')
const https = require('https')
const app = express()
app.get(’/’, (req, res) => {
res.send(‘Hello HTTPS!’)
})
https.createServer({
key: fs.readFileSync(‘key.pem’),
cert: fs.readFileSync(‘cert.pem’)
}, app).listen(3000, () => {
console.log(‘Listening…’)
})
Si vous utilisezcreate-react-app
, changer lastart
script dans lepackage.json
fichier vers:
"start": "export HTTPS=true&&SSL_CRT_FILE=cert.pem&&SSL_KEY_FILE=key.pem react-scripts start",Look at your framework/library documentation on the instructions on how to pass the certificate and key to the app.
More network tutorials:
- Introduction to WebSockets
- How HTTP requests work
- The HTTP Request Headers List
- The HTTP Response Headers List
- HTTP vs HTTPS
- What is an RFC?
- The HTTP protocol
- The HTTPS protocol
- The curl guide to HTTP requests
- Caching in HTTP
- The HTTP Status Codes List
- What is a CDN?
- The HTTP/2 protocol
- What is a port
- DNS, Domain Name System
- The TCP Protocol
- The UDP Protocol
- An introduction to REST APIs
- How to install a local SSL certificate in macOS
- How to generate a local SSL certificate
- How to configure Nginx for HTTPS
- A simple nginx reverse proxy for serving multiple Node.js apps from subfolders
- What is a reverse proxy?