Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am kind of in over my head with my current small project. (although it should not be that hard)

I am trying to run multiple webpages using docker on my Pi (for testing purposes) which should all be reachable using the PI's IP.

I currently run a minimL LIGHTTPD: (based on the resin/rpi-raspbian image)

docker run -d -v <testconfig>:/etc/lighttpd -p <pi-ip>:8080:80 <image name>

(this server is reachable using the browser on pi and on other computers in the network)

For nginx I run another container with with a simple config (starting with http://nginx.org/en/docs/beginners_guide.html), containing a webpage and images to test the container config. this container is reachable using <pi-ip>:80

then I tried to add a proxy to the locations: (I played around so now there are 3 locations for the same redirect)

location /prox1/{
  proxy_pass http://<pi-ip>:8080
}
location /prox2/{
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_pass http://<pi-ip>:8080
}
location /prox3/{
  fastcgi_pass <pi-ip>:8080;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param QUERY_STRING $query_string
}

Version 1&2 give a 404 (I tried adding a rewrite, but then I ′nginx redirected on itself due to the /prox1/ being cut). Version 3 yields a timeout.

Now I am not sure if I still have to dig on the nginx side, or I have to add a connection on the docker side between the containers.

PS: the Pi is running ArchForArm (using Xfce as desktop) because I couldn't find docker-compose in the raspberian repository.

-- EDIT ---: I currently start everything manually. (so no compose file)

the LIGHTTPD is started with:

docker run -d --name mylighttpd -v <testconfig>:/etc/lighttpd -p <pi-ip>:8080:80 <image name>

if I understood it correctly it is now listening on the local network (in the range of <pi-ip>) port 8080, which represents the test web-servers port 80. (I have added ..name so it is easier to stop it.)

the nginx is started like:

docker run --name mynginx --rm -p <pi-ip>:80:80 -v <config>:/data <image name>

The 8080 was added in the expose in the Docker file.

I current think I misunderstood the connection for two clients on the same machine, and should add a Virtual network, I am currently trying to find some docks there.

PS: I am not using the already existing nginx-zeroconf from the repo because it tells me it cant read the installed docker version. (and the only example for using that with composer also needs another container which seems unavailable for my architecture.)

-- edit2 --: For the simple proxy_pass the problem could be the URL. I added a deeper folder "prox1" in the "www" folder, containing an index file, and that one is schown when i ask for the page.

It seems like <pi-ip>:80/prox1/ is redirected to <pi-ip>:8080/prox1/ but if I try rewrite it (inside "location /prox1/") it seems to first delete the prox1, and then decides it now is part of the original location. <pi-ip>:80/

PS: I am aware that it might be a better design to place the system inside another connection than "bridge" and only expose the proxy, but i am trying to learn this stuff in small steps.

-- edit3 --: Trying compose now, but it seems I have encounters another part I don't understand (why I wanted to get it work without compose first).

I try to follow http://docs.master.dockerproject.org/compose/compose-file/#ipv4-address-ipv6-address

networks:
  backbone:
    driver: bridge
    ipam:
      driver: default
      config:
       - subnet: 172.16.238.0/16
         gateway: 172.16.238.1
services:
  nginx:
    image: <nginx-image>
    ports: 80:80
    volumes:
     - <config>:/data
    depends_on:
     - lighttpd
    networks:
      backbone:
        ipv4_address: 172.16.238.2
 lighttpd:
    image: <lighttpd-image>
    ports: 8080:80
    volumes:
     - <testconfig>:/etc/lighttpd
    networks:
      backbone:
        ipv4_address: 172.16.238.3

Now I have to find out why i get "User specific IP address is supported only when connecting to networks with user configured subnets", I assume the main networks block creates a network called "backbone".

-- edit4 --: It seems ip blocks have to be written different to all the docks I have seen, the correct form is:

...
    networks:
      backbone:
        ipv4_address: 172.16.0.2/16
...

now I have to figure out how to drop the part of the URL, and I am good to go.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
103 views
Welcome To Ask or Share your Answers For Others

1 Answer

The core problem seems to have been missing nginx parameter proxy_redirect, i found rambling trough the docks, the current nginx.conf is: (/data/www contains a index.html with a relative link to some images in /data/images)

worker_processes auto;
events {
  worker_connections 1024;
}
http {
  server {
    listen 80;
    location / {
      root /data/www;
    }
    location /images/ {
      root /data;
    }
    location /prox0/{
      proxy_pass http://lighttpd:80;
      proxy_redirect default;
      proxy_buffering off;
    }
  }
}

manual starting on local Ip seems to work, but docker-compose is easyer: (if compose is not used replace lighttpd:80 with the ip & port used for starting the server.)

networks:
  backbone:
    driver: bridge
    ipam:
      driver: default
      config:
       - subnet: 172.16.238.0/16
         gateway: 172.16.238.1
services:
  nginx:
    image: <nginx-image>
    ports: 80:80
    volumes:
     - <config>:/data
    depends_on:
     - lighttpd
    networks:
      backbone:
        ipv4_address: 172.16.0.2
 lighttpd:
    image: <lighttpd-image>
    ports: 8080:80
    volumes:
     - <testconfig>:/etc/lighttpd
    networks:
      backbone:
        ipv4_address: 172.16.0.3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...