Camunda Webapp 的 Nginx 配置

Nginx Config for Camunda Webapp

我正在使用 nginx 反向代理配置 camunda webapp。应用程序使用位置/(根路径)加载得很好。但我需要使用可读的位置路径访问它,例如/过程/。我尝试了很多重写和重定向,但没有成功。 在根路径加载所有静态内容,但在其他位置路径加载失败。我是 Nginx 的新手,所以如果我遗漏了一些非常微不足道的东西,那将是完全合理的。

这是我的配置,位置为根路径:

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;
  }
}

在另一个上下文中,如果我尝试在 proxy_pass 中提供完整的 URL(请参阅下面的配置)那么它可以工作但是浏览器 URL 完全更改为 proxy_pass URL。(我什至尝试用 proxy_redirect 来保留原来的 URL 但它不起作用)

server {

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

  location /process/ {
  rewrite ^\/(?>[process]+)(\/.*)  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;
  }
}

任何类型的信息或帮助将不胜感激。提前致谢。 贝拉再见!

我认为诀窍是将 nginx 的 location context 指定为应用程序的 context path

此外,请删除 url 重写,因为这里不需要。