Interviews1 answer
1 Answer
To serve your Angular application over HTTPS, you can use the Angular CLI with a self-signed SSL certificate or configure SSL in your hosting environment.
Option 1: Use Angular CLI with a Self-Signed Certificate
Generate SSL Certificate (using OpenSSL):
code :
openssl genrsa -out ssl.key 2048
openssl req -new -key ssl.key -out ssl.csr
openssl x509 -req -days 365 -in ssl.csr -signkey ssl.key -out ssl.crt
2. Update angular.json: Add SSL configuration under the serve section:
"serve": {
"options": {
"ssl": true,
"sslKey": "path/to/ssl.key",
"sslCert": "path/to/ssl.crt"
}
}
3. Serve with HTTPS: Run:
ng serve --ssl --ssl-key "path/to/ssl.key" --ssl-cert "path/to/ssl.crt"
Option 2: Use SSL at the Server Level
Get an SSL certificate from a trusted Certificate Authority (e.g., Let’s Encrypt).
Configure the certificate on your web server (e.g., Nginx, Apache) or hosting provider.
Redirect all HTTP traffic to HTTPS for production environments.
Sanjeev VishwakarmaPosted Nov 26, 2024, 8:21 AM EST
