How to use certificate in https Apache server with client Java <p>I'm using an Apache server to provide a https access to some files in this server. The client use Java program to access these files via a proxy.</p> <p>In my apache configuration:</p> <pre><code>SSLCertificateFile /etc/apache2/ssl/apache.pem </code></pre> <p>The structure of the file <code>apache.pem</code>: </p> <pre><code>-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- -----BEGIN CERTIFICATE----- -----END CERTIFICATE----- </code></pre> <p>The client code is:</p> <pre><code>public static void main(String[] args) throws IOException { URL website = new URL("https://mywebsite.com/file.zip"); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream("test.zip"); fos.getChannel().transferFrom(rbc, 0, 1 &lt;&lt; 24); } </code></pre> <p>The error is </p> <pre><code>Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No name matching website.com found at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1697) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:257) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:251) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1165) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:609) at sun.security.ssl.Handshaker.process_record(Handshaker.java:545) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:945) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1190) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1217) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1201) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:440) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1139) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) at java.net.URL.openStream(URL.java:1031) at HelloWorld.main(HelloWorld.java:38) </code></pre> <p>What I need to do to get Java understand my certificate? Do I need to regenerate the certificate with apache tool or java keytool? Thanks</p>