Running OpenEMR on Nginx Behind Nginx Reverse Proxy

Situation
I was running openemr on xampp, so
I wanted to migrate openemr to nginx
and i did according to the docs

My Situation is that i have many systems that needs to be exposed outside
and for that i am using nginx as a reverse proxy, it’s my entry point on the network because it has some additional features like security WAF and it’s the only component that has an external Public IP

Right now, Openemr is partially working meaning that some tabs and portals not working and i can’t figure out why
is it a URL Rewrite thing or openemr doesn’t work perfectly behind a reverse proxy or what

here’s screenshots from the non working portals

and here’s my configuration
for the Web Server

server {
    listen 80;
    listen 443 ssl;
    server_name openemr-uat.domain.com nanoemr.domain.com;
    ssl_certificate /etc/nginx/certs/cert.pem;
    ssl_certificate_key /etc/nginx/certs/key.pem;

    root /var/www/openemr;

    index index.html index.htm index.php;

    if (!-e $request_filename) {

            # Needed for zend to work
            rewrite ^(.*/zend_modules/public)(.*) $1/index.php?$is_args$args last;

            # Needed for patient portal to work
            rewrite ^(.*/portal/patient)(.*) $1/index.php?_REWRITE_COMMAND=$1$2 last;

            # Needed for REST API/FHIR to work
            rewrite ^(.*/apis/)(.*) $1/dispatch.php?_REWRITE_COMMAND=$2 last;

            # Needed for OAuth2 to work
            rewrite ^(.*/oauth2/)(.*) $1/authorize.php?_REWRITE_COMMAND=$2 last;
        }


    location ~* \.php$ {
        try_files $uri $uri/ =404;
        fastcgi_index  index.php;
        fastcgi_pass unix:/var/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }


    location ~ /\.ht {
        deny all;
    }

	# restrict/protect certain files
	include globals.conf;

	# deny access to writable files/directories
	location ~* ^/sites/*/(documents|edi|era) {
	deny all;
	return 404;
	}

	# deny access to certain directories
	location ~* ^/(contrib|tests) {
	deny all;
	return 404;
	}

	location ~* ^/(admin|setup|acl_setup|acl_upgrade|sl_convert|sql_upgrade|gacl/setup|ippf_upgrade|sql_patch)\.php {
	deny all;
	return 404;
	}

}

and here’s my reverse proxy config

server {
        listen 80;
        listen 443 ssl;
        ssl_certificate /etc/nginx/nginx-shared/certs/domain.com/fullchain_domain_com.pem;
        ssl_certificate_key /etc/nginx/nginx-shared/certs/domain.com/key_domain_com.key;

        server_name openemr-uat.domain.com;


        location / {
                proxy_pass http://NANOEMRUATDXB;
                proxy_set_header Host $host;
                proxy_set_header Upgrade $http_upgrade;
                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 http;
        }

}

Note: When i used the cmd to curl the same failing URL that returning “Oh Snap” From the reverse proxy it worked

OpenEMR Version
I’m using OpenEMR version 7

Browser:
I’m using:
all browsers(Mozilla/ Chrome/ Opera)
Operating System
I’m using: Ubuntu 22.04

Search
Did you search the forum for similar questions?
Yes and couldn’t find any
Logs
Did you check the logs? nothing useful, nginx nginx debug logging showing that the request are being constructed correctly and passed to FPM for processing but i am still getting “Oh Snap!”
Was there anything pertinent in them?
Please paste them here (surround with three backticks (```) for readability.
You can also turn on User Debugging under Administration->Globals->Logging User Debugging Options=>All

@geromoss Gerardo
@gutiersa Sandra

Any help is highly appreciated as i am stuck on this for over a week

@brady.miller
@XcrigX

Any help is highly appreciated as i am stuck on this for over a week

@Gerardo_Garcia

If you know any info that can help me here
kindly share them

Please post FPM logs.

I haven’t looked at this thoroughly yet but, of the top of my head, if its not Nginx, and not rewriting, then could it be PHP? (But would it curl?)

I’m not sure. What do FPM logs say?

I am not familiar with Nginx as a reverse proxy.

I curl it from both The Reverse Proxy and The Web Server Itself
it does curl without throwing that “Oh Snap” Error

but from outside it’s not working

i also tried forwarding the traffic directly to the openemr (which is the internal nginx)
everything worked fine

so i am sure missing something on the reverse proxy side
when i openemr source code for the word “_REWRITE_COMMAND”
i found many php files using that to inspect the request and manipulate it