2

I have used self-signed certificate in nginx. The request from UI(React js) is hitting in the backend, but NGINX is not passing the headers to the backend. My nginx configuration file is as follow:

server {
        listen 443 ssl;
        ssl on;
        server_name SERVER_NAME;
        ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
        ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
        #add_header Strict-Transport-Security max-age=31536000;
        add_header Cache-Control no-cache;
        location / {
                root  PATH_TO_FRONTEND;
                try_files $uri $uri/ /index.html$is_args$args;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
        location ~* api/(.*) {
                proxy_pass http://127.0.0.1:8080$request_uri; // BACKEND
                proxy_redirect off;
                proxy_set_header Host $host;
                add_header Cache-Control no-cache;
        } }

I get the following error in the browser:

An SSL certificate error occurred when fetching the script.

sw.js Failed to load resource: net::ERR_INSECURE_RESPONSE

login:1 Uncaught (in promise) DOMException: Failed to register a ServiceWorker: An SSL certificate error occurred when fetching the script.

2
  • Are you trying to debug the fact that "NGINX is not passing the headers to the backend" or the browser error? If you're using a self-signed certificate, it sounds natural that your browser would not accept it. Commented Dec 23, 2017 at 7:50
  • @kshikama I am a bit confused why NGINX is not passing the headers to the backend. Commented Dec 23, 2017 at 7:52

2 Answers 2

1

Try adding

proxy_pass_header Server;

to your location block. It effectively says to pass through the sender's headers to the backend.

Sign up to request clarification or add additional context in comments.

7 Comments

It is still not passing the headers to the backend @kshikama
Hmm no idea then. If you don't get any other answers, I suggest turning off SSL (switching to port 80) and commenting out the cache-control no-cache and see if that is affecting anything.
I want SSL for one of my requirements. Anyhow, Thanks @kshikama for your effort.
Yeah I didn't suggest to permanently turn it off - just to debug.
It works if SSL is off. I think there is something wrong in the NGINX configuration. The request hits the backend but NGINX prevents the headers.
|
0

I had the same issue. Apparently nginx blocks custom headers which have underscore in them. Please look at this if you are using underscore in your headers: https://serverfault.com/a/1003572

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.