1

I have been attempting to configure nginx reverse proxy with php support in docker compose that runs an app service on port 3838. I want the app to run the nginx-proxy on port 80. I have combed through several tutorials online but none of them has helped me resolve the problem. I also tried to follow this https://github.com/dmitrym0/simple-lets-encrypt-docker-compose-sample/blob/master/docker-compose.yml but it didn't work. Here is my current docker compose file.

docker-compose.yml

version: '3'
services:
 nginx-proxy:
   image: jwilder/nginx-proxy
   ports:
     - "82:80"
     - "444:443"
   volumes:
     - "/etc/nginx/vhost.d"
     - "/usr/share/nginx/html"
     - "/var/run/docker.sock:/tmp/docker.sock:ro"
     - "/etc/nginx/certs"

app:
 build:
  context: .
  dockerfile: ./app/Dockerfile
 image: rocker/shiny
 container_name: docker-app
 restart: always
 ports:
  - 3838:3838

Am I missing something. Sometimes I see virtual_host environment variables include in the docker-compose file. Is that needed? Also do I have to manually configure nginx config files and attach them to the jwilder/nginx-proxy dockerfile? I a newbie at docker and and I really need some help.

1 Answer 1

1

Please refer to the Multiple Ports section of the nginx-proxy official docs. In your case, besides setting a mandatory VIRTUAL_HOST env variable (without this a container won't be reverse proxied by the nginx-proxy service), you have to set the VIRTUAL_PORT variable as the nginx-proxy will default to the service running on port 80, but your app service is bind to 3838 port.

Try this docker-compose.yml file to see if it works:

version: "3"

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  app:
    build:
      context: .
      dockerfile: ./app/Dockerfile
    image: rocker/shiny
    container_name: docker-app
    restart: always
    expose:
      - 3838
    environment:
      - VIRTUAL_HOST=app.localhost
      - VIRTUAL_PORT=3838
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.