nginx Redirect url with hospital name.

Hi Team, I am using docker image of openmrs. i try to put hospital name infront of openmrs like on ngnix. Ngnix is not forwarding to openmrs dokcer image. Anyone tried like this.

Thanks Prapa


I have multiple instances doing that.

So, for example, the demo docker container is exposing port 8080 (for the container) on port 8080 (on the host). Which means that if I run in the host ‘curl -vvv http://localhost:8080/openmrs’, I get an answer.

Then I have nginx installed on the host, pointing a certain domain (
in nginx vhosts to http://localhost:8080/openmrs (and setting up HTTPS as well). The ‘acme’ part is about the certificate generated by letsencrypt, so you can ignore unless you are using letsencrypt for your SSL/TLS certificates.

Note that I’m using ansible to deploy nginx configuration (and my whole infrastructure is completely automated), so you cannot just copy and paste that it won’t work.

@cintiadr Thanks for the reply. I am also trying a similar setup. I am not creating a load balancer for every hospital. just trying like in ngnix which redirect to http://localhost:8080/openmrs.

and also, we are i could see ansible script for automation.

Thanks Prapa

If you are planning on using ansible, start from their main website and tutorial

Our infrastructure is also open source and you can see we are using geerlingguy.nginx galaxy module for nginx.

Thank you. Is it possible to build url like in ngnix which redirect to http://localhost:8080/openmrs. It tested but redirection is not working.

Yes, @prapakaran, that’s possible.

That said, we cannot guess why your setup isn’t working. First, let’s not jump to conclusions.

Can you confirm that running locally ‘curl -vvv http://localhost:8080/openmrs’ works? If that doesn’t work, you need to fix your docker setup to expose port 8080.

Then, if you’d like me to take a look on your nginx, you need to (1) copy here the ‘server’ part of your nginx configuration, including your ‘location’ and (2) let me know exactly what happens when you run `curl -vvvv

I can try to help you, but it’s hard without more information

@cintiadr Yes, It looks i was not went to very detail. Please find my docker-compose.yaml for ngnix and openmrs.

Nginx proxy config

server {
listen 443 ssl default_server;

root /config/www;
index index.html index.htm index.php;

server_name _;

# enable subfolder method reverse proxy confs
include /config/nginx/proxy-confs/*.subfolder.conf;
    # all ssl related config moved to ssl.conf
include /config/nginx/ssl.conf;

client_max_body_size 0;

location / {
	return 301 https://$http_host/openmrs$request_uri;

location /hospitalname1/openmrs {
           # proxy_set_header Host $host;
           # proxy_set_header X-Real-IP $remote_addr;
	include /config/nginx/proxy.conf;
	proxy_pass http://refapp:8080/openmrs;

Nginx docker-compose

 version: '2'
    image: linuxserver/letsencrypt
      - NET_ADMIN
      URL: $URL
      VALIDATION: http
      PGID: 1000
      PUID: 1000
      TZ: $TZ 
      - proxy:/config
      - ./proxy/openmrs.conf:/config/nginx/site-confs/default
      - 443:443
      - 80:80 #optional
    restart: unless-stopped
      name: my-pre-existing-network  

Openmrs Docker-compose

version: '2'
    image: mysql:5.6
      - --character-set-server=utf8
      - --collation-server=utf8_general_ci
      MYSQL_ROOT_PASSWORD: "password"
      MYSQL_DATABASE: "openmrs"

      - db
    build: .
      - db:database
      - 8080:8080
      DB_HOST: database
      DB_DATABASE: "openmrs"
      DB_USERNAME: "root"
      DB_PASSWORD: "password"
      DB_CREATE_TABLES: "true"
      DB_AUTO_UPDATE: "false"
      MODULE_WEB_ADMIN: "false"
      OPENMRS_ADMIN_PASSWORD: "MyCustomPassword123" # Note: has no effect if DB_CREATE_TABLES set to false
      TZ: "America/New_York"

Oh, so you decided to put nginx inside a docker container as well. That’s a pretty important difference from how I did it.

I believe you don’t want this (the default redirect when you land to your domain):

location / {
	return 301 https://$http_host/openmrs$request_uri;

Also, you need both refapp and proxy to be on the my-pre-existing-network; right now you only have nginx I believe.

You can also ‘enter’ the nginx docker container to investigate any connectivity problem:

docker exec -it <container-name-or-id> sh

@cintiadr will check nginx logs. I am just thinking docker multihost option for different hospitals. I could run ngnix in one box and communicate different host via docker multihost option.

I have multiple openmrs instances running on the same machine as well (each one on its own docker container), but I decided to have nginx on the host (instead of a docker container) because I thought it would be easier to maintain on my setup (and to investigate problems as well).

Both should work exactly the same after setting it up.

@cintiadr One more question for adding order entry module with docker. Is there way to add like other easy way add the module with docker image. the steps looks little different below.


The easiest way is to make a persisted volume from folder ‘/usr/local/tomcat/.OpenMRS/’, and install using the OpenMRS admin page.

As far as you don’t destroy the volume (for example, with docker-compose down -v), the module will continue to be installed there.

You can see the example from modules-refapp.

@cintiadr Can i copy zip file(link below) or any other format like omod.

You should use the admin screen, @prapakaran