Generate a Self-Signed SSL Certificate Create a directory for your SSL certificates:
sudo mkdir -p /etc/nginx/ssl
Generate the private key and self-signed certificate:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/nginx/ssl/self-signed.key \
-out /etc/nginx/ssl/self-signed.crt
When prompted, fill in the required fields (or leave them blank for defaults). For Common Name, use your local server's hostname or IP.
Update firewall rules
sudo firewall-cmd --add-service=https --permanent sudo firewall-cmd --reload
edit nginx conf
/etc/nginx/conf.d/https.conf
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/ssl/self-signed.crt;
ssl_certificate_key /etc/nginx/ssl/self-signed.key;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
server {
listen 80;
server_name localhost;
return 301 https://$host$request_uri;
}
This configuration sets up Nginx to:
Test and reload nginx
nginx -t sudo systemctl reload nginx
To stop Safari on iOS from complaining about a self-signed certificate, you need to manually trust the certificate on your iPhone or iPad. Here's how to do it:
.crt
file (e.g., self-signed.crt
) from your server or computer..crt
file to yourself.Open the .crt
file on your iOS device:
Install the profile:
By default, iOS will not fully trust the certificate. To mark it as trusted:
Open the Settings app.
Navigate to: General > About > Certificate Trust Settings
Under the "Enable Full Trust for Root Certificates" section:
Open Safari and visit the HTTPS site using the self-signed certificate.
Hostname vs. IP Address: If the certificate was created for a hostname (e.g., myserver.local
) and you’re accessing the server via an IP address, the certificate won’t match. To fix this:
/etc/hosts
file on the server to use the hostname.