How to Quickly Set Up a Local HTTPS Development Environment
This guide explains why HTTPS is required for local web development, demonstrates how to create a self‑signed root CA and a wildcard domain certificate with OpenSSL, shows how to trust the root certificate on macOS, and provides example Webpack devServer and hosts file configurations for a secure local workflow.
Local development often needs HTTPS because many Web APIs (e.g., navigator.clipboard ) only work in a secure context; browsers treat https://localhost and window.isSecureContext as secure, and some HTTP requests may be rejected by HTTPS servers.
First, generate a self‑signed root CA using OpenSSL:
openssl genrsa -des3 -out localCA.key 2048Then create the root certificate (valid for 5 years):
openssl req -x509 -new -nodes -key localCA.key -sha256 -days 1825 -out localCA.pemImport localCA.pem into macOS Keychain Access, set it to "Always Trust", and confirm the trust status.
Next, create a wildcard domain certificate. Generate a private key for the domain:
openssl genrsa -out ext.yourdomain.com.key 2048Create a Certificate Signing Request (CSR):
openssl req -new -key ext.yourdomain.com.key -out ext.yourdomain.com.csrPrepare an extension file (e.g., ext.yourdomain.com.ext ) with the following content:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.yourdomain.comSign the CSR with the root CA to obtain the wildcard certificate:
openssl x509 -req -in ext.yourdomain.com.csr \
-CA localCA.pem -CAkey localCA.key \
-CAcreateserial -out ext.yourdomain.com.crt \
-days 1825 -sha256 -extfile ext.yourdomain.com.extCopy the generated ext.yourdomain.com.key and ext.yourdomain.com.crt to your project and configure Webpack devServer:
devServer: {
proxy: { '*': 'http://127.0.0.1:9360' },
port: 443,
https: {
key: fs.readFileSync(path.join(__dirname, 'ext.yourdomain.com.key')),
cert: fs.readFileSync(path.join(__dirname, 'ext.yourdomain.com.crt'))
},
host: 'dev.yourdomain.com',
allowedHosts: ['dev.yourdomain.com'],
watchContentBase: true
}Add host entries to your /etc/hosts file:
127.0.0.1 dev.yourdomain.com
127.0.0.1 test.yourdomain.comAfter restarting the services, the local site can be accessed via https://dev.yourdomain.com . Note that the wildcard *.yourdomain.com only covers one level (e.g., dev.yourdomain.com or test.yourdomain.com ); deeper subdomains like dev.h5.yourdomain.com require a separate certificate.
360 Tech Engineering
Official tech channel of 360, building the most professional technology aggregation platform for the brand.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.