• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question Nginx proxy settisng for Node.js app

Peter Carlsson

Basic Pleskian
Witch is more correct and why?

Code:
location ~ / {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://localhost:8080;
}

or


Code:
location ~ / {
    proxy_pass http://localhost:8080;
    proxy_http_version 1.1;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    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-NginX-Proxy true;

    proxy_cache_bypass $http_upgrade;
}
 
Hello @Peter Carlsson ,

proxy settings for nginx are not the same depending on the nodejs app you want to use.

For example with ghost, the official nginx configuration is :
Code:
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
    }
[code]

But   as you can see ,    it's   better to use the   X-Forwarded-For header   and the     X-Forwarded-Proto  header to declare to your nodejs app  the proxy and the client original IP   with the protocol used for the connection. Otherwise, you may see the proxy IP instead of the client  IP.
In case of compatibility issues with HTTP/2 ,   you can use the proxy_http_version directive to   change the   protocol used   between your nodejs app and the proxy (nginx).
 
Back
Top