NGINX Reverse Proxy Configuration with Cloudflare


We are looking to use TruDesk ticketing application for our company and at the moment we have created the environment required and clone the repo from Github, I can see the install opening using the IP and Port but when I try to add the revese proxy it does not work using the sample config file for default conf file.

I have tried multiple ways searching on google but yet not able to configure it and everytime either the nginx shows error or when I try to open the site it says - “ERR_TOO_MANY_REDIRECTS”

Below is the environment I am using -

Ubuntu 20.04
AWS Server
Elatisc Search
Cloudflare for DNS

Below you can the conf file configuration modified by me to be used with Cloudflare where the SSL setting is flexible.

Currently, when we load the website it says - Web server is down Error code 521, when SSL is turned off it says - “ERR_TOO_MANY_REDIRECTS”

Default server configuration for TruDesk configuration on AWS EC2 Server and Cloudflare Flexible SSL

http {
access_log /var/log/nginx/access.log main;

sendfile        on;
keepalive_timeout  65;

upstream socket_nodes {
    # IP Address of Host running Trudesk

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

    location ~ ^/(uploads/) {
            root /usr/src/trudesk/public;
            access_log off;
            expires modified +1h;

    location / {
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_cache one;
            proxy_cache_key trudesk$request_uri$scheme;
            proxy_pass http://socket_nodes;

            proxy_redirect http://socket_nodes https://socket_nodes;

    # redirect server error pages to the static page /50x.html
    # in the even that the trudesk instance is down, these pages will serve.
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {


Request you to kindly help me to resolve the nginx configuration issue asap.