search

Home  >  Q&A  >  body text

404 error occurs in jenkins using nginx reverse proxy

nginx configuration:

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

Use a browser to access http://ip/jenkins, it will jump to http://ip/login?from=%2Fjenkins, and a 404 error will appear.

But use the nginx configuration below

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

Using a browser to access http://ip will jump to http://ip/login?from=%2Fjenkins, but it can be accessed normally. Why is this?

If I want to implement http://ip/jenkins access method, how to configure nginx?

PHPzPHPz2747 days ago1784

reply all(1)I'll reply

  • 習慣沉默

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

    Probably like this

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

    reply
    0
  • Cancelreply