Multiples instances on same sever with nginx reverse proxy

Hi, I am deploying two instances of dhis2 on one server with nginx as reverse proxy. both instances are working but I am struggling with the reverse proxy. I want to use one domaine name and access the second instance by adding a subfolder to the domain name in the browser. The first instance is deployed on docker and the second one is deployed locally on the server running on port 8080 in a subfolder of /opt.

My configuration is similar to the following but when I access the first one it is working but the second one is not working it keeps bringing me back to the first one

server {
listen 80;
server_name www.dhmis.org dhmis.org;

    # Proxy  pass to servlet container
    location / {
            proxy_pass http://localhost:8090;
            include /etc/nginx/proxy_params;
    }

    location /training {
            root /home/hisp/tomcat-dhis-training/webapps/training;
            proxy_pass http://localhost:8080;
            include /etc/nginx/proxy_params;
    }


}
1 Like

Hello @Malick

Based on your configuration, I believe the second DHIS2 instance configuration causes the issue. I think the proxy pass should be to http://locahost:8080/training instead of just http://locahost:8080. I also don’t think it is necessary to add the root variable.

I would also recommend you check out the official server tools that is maintained by the DHIS2 core team for better management of your instances. You can find it here

Thank you for your answer. I have removed the root variable and I also put “training” at the end of the proxy_pass. Now it seems working but when I go to maintenance It does not work maintenance is not showing. it is trying to go the internal IP when i look in the network tab in developer tools

Hello @Malick

Glad to hear the first solution worked.

As for the maintenance issue, can you try to add the following configuration in the nginx config of both DHIS2 instances

proxy_set_header Host $http_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_redirect off;
proxy_set_header X-Frame-Options "SAMEORIGIN";  # To mitigate the risk of clickjacking attacks
proxy_set_header X-Content-Type-Options "nosniff"; # drive-by download attacks
proxy_set_header X-Forwarded-Port 443;
proxy_hide_header Strict-Transport-Security;
proxy_hide_header X-Powered-By;
proxy_hide_header Server;