K
K
kr_ilya2019-11-15 19:09:54
Nginx
kr_ilya, 2019-11-15 19:09:54

Why doesn't Nginx return headers set by helmet.js to node.js?

The problem is that on localhost, without nginx proxying, requests to node.js return such headers
5dcecccf0ff08712550408.png
. When proxying requests through Nginx, these headers are not picked up. Why? How to fix?
BUT YES:

const helmet = require('helmet')
app.use(helmet())

Nginx:
map $sent_http_content_type $expires {
    "text/html"                 epoch;
    "text/html; charset=utf-8"  epoch;
    default                     off;
}

server {
    listen          80;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate 2
    ssl_certificate_key 1        # the port nginx is listening on
    server_name 1
    root /root/wutils;

    if ($host ~* www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*)$ https://$host_without_www$1 permanent;
    }

    gzip            on;
    gzip_types      text/plain application/xml text/css application/javascript;
    gzip_min_length 1000;

    location /api/ {
        #return 503;
        
        proxy_redirect                      off;
        proxy_set_header Host               $host;
        proxy_set_header X-Real-IP          $remote_addr;
        proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        proxy_set_header                    Upgrade $http_upgrade;
        proxy_set_header                    Connection "upgrade";
        proxy_read_timeout          30m;
        proxy_connect_timeout       30m;
        send_timeout                30m;
        proxy_pass https://127.0.0.1:3000/;
        proxy_ssl_server_name on;


    }

    error_page 500 502 503 504 /50x.html;

    location = /50x.html { 
        root /var/www/errors;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vreitech, 2019-11-15
@fzfx

try adding for location:
proxy_pass_header имя_заголовка;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question