Node JS nginx & pm2 config

This is for personal reference and I make no guarantees any of this will work for you. I no longer need it, but don’t want to lose this either. Future reference, and all that.

upstream pm2_nodejs_upstream {
    server node:4000;
    keepalive 64;
}

server {
    listen 80;
    server_name api.example.com;
    root /data;

    # location / {
    #     return 200 "Hello from Example.com";
    # }
    
    location / {
    	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    	proxy_set_header Host $http_host;
    	proxy_set_header X-NginX-Proxy true;
    	proxy_http_version 1.1;
    	proxy_set_header Upgrade $http_upgrade;
    	proxy_set_header Connection "upgrade";
    	proxy_max_temp_file_size 0;
    	proxy_pass http://pm2_nodejs_upstream/;
    	proxy_redirect off;
    	proxy_read_timeout 240s;
    }

    error_log /var/log/nginx/api.example.com_error.log;
    access_log /var/log/nginx/api.example.com_access.log;
}

 

Published by

Code Review

CodeReviewVideos is a video training site helping software developers learn Symfony faster and easier.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.