0

I'm trying to get Nginx working as a reverse proxy for the Transmission web client. Both are in separate Docker containers with Docker Compose.

Ive read previous similar questions, but these have not worked for me: https://unix.stackexchange.com/questions/64812/get-transmission-web-interface-working-with-web-server

https://stackoverflow.com/questions/15391073/nginx-transmission-daemon-url-rewrite

Nginx gives me the error:

[error] 6#6: *3 "/etc/nginx/html/transmission/web/index.html" is not found (2: No such file or directory), client: 172.18.0.1, server: torrent.localhost, request: "GET /transmission/web/ HTTP/1.1", host: "torrent.localhost"

This makes me suspect that the proxy_pass is not working correctly as its still trying to grab the html file from the file system.

Any help would be very much appreciated!

docker-compose.yml:

version: "2"
services:
  nginx:
    image: nginx
    container_name: nginx-proxy
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./www:/data/www
    ports:
    - "80:80"
    - "443:443"

  transmission:
    image: linuxserver/transmission
    container_name: transmission
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
      - USER=username
      - PASS=password
    volumes:
      - ./transmission/config:/config
      - ./transmission/downloads:/downloads
      - ./transmission/watch:/watch
    ports:
      - "9091:9091"
      - "51413:51413"
      - "51413:51413/udp"
    restart: unless-stopped

nginx.conf:

events {
}

http {
    server {
        listen 80;
        server_name localhost 127.0.0.1;
        root /data/www;
        location = / {
            index index.html;
        }
    }

    server {
        server_name torrent.localhost;
        location = / {
            proxy_read_timeout 300;
            proxy_pass_header  X-Transmission-Session-Id;
            proxy_set_header   X-Forwarded-Host $host;
            proxy_set_header   X-Forwarded-Server $host;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://transmission:9091;
        }
    }
}

index.html:

hello world!
0

Your problem lies in the equal sign after "location". The equal sign can be used if the location needs to match the EXACT request URI.

You might want to remove the equal sign ("=") like this:

server {
    server_name torrent.localhost;
    location / { # <-- remove "=" sign
        proxy_read_timeout 300;
        proxy_pass_header  X-Transmission-Session-Id;
        proxy_set_header   X-Forwarded-Host $host;
        proxy_set_header   X-Forwarded-Server $host;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://transmission:9091;
    }
}
1

You can achieve by adding your containers into a single network. you can define the network in docker-compose file. Example given below,

version: "2"
services:
  nginx:
    image: nginx
    container_name: nginx-proxy
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./www:/data/www
    ports:
    - "80:80"
    - "443:443"
    networks:
      NETWORKNAME:
        ipv4_address: 10.5.2.1

  transmission:
    image: linuxserver/transmission
    container_name: transmission
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/London
      - USER=username
      - PASS=password
    volumes:
      - ./transmission/config:/config
      - ./transmission/downloads:/downloads
      - ./transmission/watch:/watch
    ports:
      - "9091:9091"
      - "51413:51413"
      - "51413:51413/udp"
    restart: unless-stopped
    networks:
      NETWORKNAME:
        ipv4_address: 10.5.2.2

networks:
  NETWORKNAME:
    driver: bridge
    ipam:
      config:
        - subnet: 10.5.0.0/16
          gateway: 10.5.0.1

Replace the NETWORKNAME as you wish. Also, select the subnet mask according to your requirements (IPs also you can pick as you wish). Then change your nginx conf as below,

server {
    listen 80;
    server_name "abc.example.com";   #your domain name
 
    location / {

        limit_except GET POST PUT HEAD DELETE OPTIONS PATCH {
             deny   all;
        }

        proxy_pass https://10.5.2.2;     #IP of your web container
        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;
        proxy_intercept_errors on;
    }
}

The below project is using an Nginx container as a reverse proxy. You can refer to that project and find more helpful information. OrangeHRM Dockerized Development Environment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.