0

I have Jenkins behind NGINX reverse proxy, both docker containers are in the same network thanks to docker compose. The only entrance to Jenkins server is through NGINX which expose 80 port. Once the request reach NGINX container then it redirects to Jenkins.

I don't get a successful response, but without NGINX reverse proxy everything works fine. How Can I solve this?

In addition, you can find some additional files like nginx default.conf and docker-compose.yml https://github.com/orbismobile/docker-nginx-jenkins-android

After setting up them:

  1. NGINX user basic auth: user1 - android(password)
  2. Jenkins admin user: user2 - ios(password)

I've tried this

curl -u user1:android http://localhost:8080/api/json?pretty=true
curl -u user2:ios http://localhost:8080/api/json?pretty=true
curl -U user2:ios -u carlos1:android http://localhost:8080/api/json?pretty=true

JENKINS DOCKERFILE

FROM jenkins/jenkins:latest
ENV JENKINS_OPTS="--prefix=/jenkins"

NGINX DOCKER FILE

FROM nginx:latest
# Install a password file creation utility to create username-password pairs
RUN apt-get update; apt-get install -y --no-install-recommends apache2-utils
RUN mkdir /etc/apache2; cd /etc/apache2; touch .htpasswd

DOCKER-COMPOSE.YAML

version: '3'
services:
  jenkinsservice:
    build: ./jenkins-service
    volumes:
      - jenkinshomevol:/var/jenkins_home  

  nginxservice:
    build: ./nginx-service
    ports:
      - "80:80"
    volumes:
      - ./nginx-service/conf.d:/etc/nginx/conf.d
      - ./nginx-service/html:/usr/share/nginx/html
    depends_on:
      - jenkinsservice

volumes:
  jenkinshomevol:   

I expect the 200 OK HTTP CODE, but the actual output is 403 FORBIDDEN HTTP CODE from Jenkins with this body --> Authentication required - You are authenticated as: anonymous

1 Answers1

0

I assume you tried the curl commands form inside the jenkins container.

This works for me:

curl -u user2:ios http://127.0.0.1:8080/jenkins/api/json?pretty=true

I think you are trying to access the wrong Jenkins URL.

Mihai
  • 9,526
  • 2
  • 18
  • 40
  • Your post says different – Mihai Apr 08 '19 at 19:44
  • I have tried the same ´´´curl -u user2:ios http://127.0.0.1:8080/jenkins/api/json?pretty=true´´´ but I get this error: curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused. I think this is because the only entrance to jenkins is through NGINX with has exposed the 80 port, this url http://localhost/jenkins/. And if I change it to this: ´´´curl -u user2:ios http://127.0.0.1/jenkins/api/json?pretty=true´´´ I get this error: Authentication required You are authenticated as: anonymous ... HTTP 403 forbidden – Carlos Leonardo Camilo Vargas Apr 08 '19 at 19:48
  • Do you have any idea about what's happening? The request reach the Jenkins server but it needs the Jenkins admin user credentials(user1:android) which for any reason my request is not passing those values, only recognize the credentials for NGINX – Carlos Leonardo Camilo Vargas Apr 08 '19 at 21:26
  • Is it possible that maybe you didn't finish the jenkins installation from the web interface? Where you put the password generated in the logs? It looks to me like that could be the problem. – Mihai Apr 09 '19 at 05:13