搜尋

首頁  >  問答  >  主體

使用nginx反向代理出現jenkins出現404錯誤

nginx配置:

server {

    listen 80;
    server_name localhost;

    location /jenkins {

      proxy_set_header        Host $host:$server_port;
      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;

      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:8081;
      proxy_read_timeout  90;
    }
  }

使用瀏覽器造訪http://ip/jenkins,會跳到http://ip/login?from=%2Fjenkins,出現404錯誤。

但使用下面的nginx配置

server {

    listen 80;
    server_name localhost;

    location / {

      proxy_set_header        Host $host:$server_port;
      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;

      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:8081;
      proxy_read_timeout  90;
    }
  }

使用瀏覽器訪問http://ip,會跳到http://ip/login?from=%2Fjenkins,但是能正常訪問,這是為什麼呢?

想實作http://ip/jenkins這種存取方式,要怎麼設定nginx?

PHPzPHPz2747 天前1785

全部回覆(1)我來回復

  • 習慣沉默

    習慣沉默2017-05-16 17:16:58

    大概是這樣

    server{
        location / {
            try_files $uri @jenkins;
         }
         
        location @jenkins {
            internal;
            proxy_pass http://127.0.0.1:8080;
        }
    }

    回覆
    0
  • 取消回覆