The certificate for this server is invalid

If you try to access a https website in iOS simulator, you will see the error below.

Error loading page
Domain: NSURLErrorDomain
Error Code: -1202
Description: The certificate for this server is invalid. You might be connecting to a server that is pretending to be "" which could put your confidential information at risk.

Follow the steps below to bypass the ssl cert validation:
1. Drag and drop the .crt file to the iOS simulator.
2. Go to Settings > General > Profile, Select the cert and click “Install”.
3. Go to Settings > General > About > Certificate Trust Settings, Turn on the “Enable Full Trust for Root Certificates” option.

Create a certificate for localhost on Mac OS

1. Generate cert

openssl req -x509 -out -keyout \
-newkey rsa:2048 -nodes -sha256 \
-subj '/' -extensions EXT -config <( \
printf "[dn]\\n[req]\ndistinguished_name = dn\n[EXT]\\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

2. Add the certificate to Keychain Access

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain

3. Update Apache config

SSLEngine on
SSLCertificateFile /Applications/AMPPS/www/my-helper.test/certs/
SSLCertificateKeyFile /Applications/AMPPS/www/my-helper.test/certs/


Apache SNI

Step 1. vim /etc/httpd/conf/httpd.conf

NameVirtualHost *:443
Include /etc/httpd/conf/extra/httpd-vhosts.conf

Step 2.  vim /etc/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:443>
    DocumentRoot "/var/www/vhosts/"
    <Directory "/var/www/vhosts/">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    ErrorLog "/var/www/vhosts/"
    TransferLog "/var/www/vhosts/"
    SSLEngine on
    SSLCertificateFile /etc/pki/tls/certs/
    SSLCertificateKeyFile /etc/pki/tls/certs/
    SSLCertificateChainFile /etc/pki/tls/certs/