How can I proxy ssl endpoint using webpack-dev-server proxy

When I try to proxy this request http://localhost:9000/rpc , I get:

 cannot proxy to https://example.appspot.com:80 (write EPROTO 101057795:error:140770FC:SSL routines: SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:) 

webpack-dev-derver config:

 devServer: { contentBase: "./", hostname: 'localhost', port: 9000, proxy: { '/rpc': { target: 'https://example.appspot.com', secure: false, changeOrigin: true // **Update-2 SOLVED** } } } 

I use fetch : fetch('/rpc' ... to make a request and Windows 10 professional to run webpack.

Without proxy: fetch('https://example.com/rpc' ... SSL request works fine.

Refresh. I had to use SSL port 443 (see Steffen's answer).
Now using: https://example.appspot.com:443

But still does not work with secure: true . The console log displays:

 cannot proxy to https://example.appspot.com:443 (Hostname/IP doesn't match certificate altnames: "Host: localhost. is not in the cert altnames: DNS:*.appspot.com, DNS:*.thinkwithgoogle.com, DNS:*.withgoogle.com, DNS:*.withyoutube.com, DNS:appspot.com, DNS:thinkwithgoogle.com, DNS:withgoogle.com, DNS:withyoutube.com") 

And with secure: false . The console reports: 404 (Not Found)

Update: SOLVED with changeOrigin: true . Docs are here .

+6
source share
2 answers
  target: 'https://example.com:80', 

It is very unlikely that port 80 is used for HTTPS. Commonly used port 443

 SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:) 

It is very likely that the server in port 80 did not respond with HTTPS, but with some HTTP error, because the message from the client was the beginning of the TLS handshake, not the expected HTTP request. But the client was expecting a TLS handshake response, not an HTTP error. That is why you get this error.

Without proxy: fetch (' https://example.com/rpc ' ... SSL request works fine.

This is because you are using https://example.com in this case, not https://example.com:80 . Since you do not provide an explicit port, it will use the default port for https, i.e. 443.

+2
source

While I use the correct config with changeOrigin: true , etc., but still meet 301 and request options and cannot reach the real server server. Until I try to clear the browser cache , it works correctly.

0
source

All Articles