1

We are making a V2 Docusaurus website.

After building the website in the server, we could well use it with https. Here is a part of my_server_block.conf:

server {
  listen  3001 ssl;

  ssl_certificate      /certs/server.crt;
  ssl_certificate_key  /certs/server.key;

  ssl_session_cache    shared:SSL:1m;
  ssl_session_timeout  5m;

  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers  on;

  location / {
    proxy_pass http://localhost:3002;
    proxy_redirect off;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Ssl on;
  }
}

In localhost, http works. However, we need to test https in localhost now. But https returns an error, though I started it by HTTPS=true yarn start: This site can’t provide a secure connection localhost sent an invalid response. ERR_SSL_PROTOCOL_ERROR:

enter image description here

Does anyone know what I should do to make https work in localhost?

Edit 1: I tried HTTPs=true SSL_CRT_FILE=certs/server.crt SSL_KEY_FILE=certs/server.key yarn start, https://localhost:3001 still returned the same error. Note that certs/server.crt and certs/server.crt are the files that make https work in our production server via ngnix:

server {
  listen  3001 ssl;

  ssl_certificate      /certs/server.crt;
  ssl_certificate_key  /certs/server.key;
SoftTimur
  • 5,630
  • 38
  • 140
  • 292

3 Answers3

1

You are using Nginx, so use it for SSL offloading (your current config) and don't start https on the Docusaurus site. So user in the browser will use https, but Docusaurus will be using http.

If you start https on the Docusaurus site and you will be proxypassing with http proxy_pass http://localhost:3002;, then it is obvious problem - connection with http protocol to https endpoint. You may proxypass with https protocol proxy_pass https://localhost:3002; of course, but that may need more advance configuration. Just keep it simple and use SSL offloading in the Nginx.

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
0

Docusaurus 2 uses Create React App's utils internally and you might need to specify the path to your cert and key as per the instructions here. I'm not familiar with the server config so I can't help you there.

Maybe this answer will be helpful - How can I provide a SSL certificate with create-react-app?

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
0

There is an issue with https support on localhost in react-dev-utils@^v9.0.3, which is a dependency of docusaurus.

https://github.com/facebook/create-react-app/issues/8075

https://github.com/facebook/create-react-app/pull/8079

It is fixed in react-dev-utils@10.1.0

think-serious
  • 1,229
  • 2
  • 12
  • 27