Nginx Config for Camunda Webapp

I am configuring camunda webapp with nginx reverse proxy. Applications is loading perfectly fine using location / (Root Path). But I need to access it using a readable location path e.g. /process/. I tried a lot with several rewrites and redirections but to no success.
At root path all the static content loads but with other location path it fails. I’m a newbie in Nginx So it would make complete sense if i’m missing something very trivial.

Here is my config with location as Root Path:

server {

  listen 8080;
  server_name abc.xyz.net;
  rewrite_log on;
  error_log /var/log/nginx/localhost.error_log notice;

  location / {

    # Simple requests
    if ($request_method ~* "(GET|POST)") {

      add_header "Access-Control-Allow-Origin" *;
    }

    # Preflighted requests
    if ($request_method = OPTIONS ) {

      add_header "Access-Control-Allow-Origin" *;
      add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
      add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
      return 200;
    }

    proxy_pass http://camunda-webapp.xyz.net;

    proxy_set_header X-Forwarded-Host $host/;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass_request_headers on;
    proxy_read_timeout 180s;
  }

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {

    root /usr/share/nginx/html;
  }
}

On another context, If I try to give full URL in proxy_pass(Refer below config) then it works but the browser URL gets completely changed to proxy_pass URL.(I had even tried with proxy_redirect to retain the original URL but it doesn’t work)

server {

  listen 8080;
  server_name abc.xyz.net;
  rewrite_log on;
  error_log /var/log/nginx/localhost.error_log notice;

  location /process/ {
  rewrite ^\/(?>[process]+)(\/.*) $1 break;

    # Simple requests
    if ($request_method ~* "(GET|POST)") {

      add_header "Access-Control-Allow-Origin" *;
    }

    # Preflighted requests
    if ($request_method = OPTIONS ) {

      add_header "Access-Control-Allow-Origin" *;
      add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
      add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
      return 200;
    }

    proxy_pass http://camunda-webapp.xyz.net/app/welcome/default;
	proxy_redirect http://camunda-webapp.xyz.net/app/welcome/default https://abc.xyz.net/process

    proxy_set_header X-Forwarded-Host $host/process;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass_request_headers on;
    proxy_read_timeout 180s;
  }

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {

    root /usr/share/nginx/html;
  }
}

Any kind of info or help will be appreciated. Thanks in Advance.
Bella Ciao!

server {
listen 9999;
server_name bpm;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:;
}
}

This is what worked for me. But the trick is to use an absolute url to go to login page like:

http://localhost:9999/app/welcome/default/#!/login

If you use any other url the redirects are all messed up and it removes the port from url and it fails.

I think the trick is to specify the same location context of the nginx as the context path of the your application.

Also, please remove url rewrite as its not needed here.

1 Like