How to configure trojan to make it fall back to the site correctly?

1.1k Views Asked by At

I use the mirror jwilder/nginx-proxy to automatically HTTPS, and I deploy the trojan-go service through the compose.yml file. The content of the compose.yml file is shown below. I can open the HTTPS website correctly by the domain name, but trojan-go does not fall back to the website correctly, and the log shows github.com/p4gefau1t/trojan-go/proxy.(*Node).BuildNext:stack.go:29 invalid redirect address. check your http server: trojan_web:80 | dial tcp 172.18.0.2:80: connect: connection refused, where is the problem? thank you very much!

    version: '3'
    services:
      trojan-go:
        image: teddysun/trojan-go:latest
        restart: always
                          
        volumes:
          - ./config.json:/etc/trojan-go/config.json
          - /opt/trojan/nginx/certs/:/opt/crt/:ro
          
        environment:
          - "VIRTUAL_HOST=domain name"
          - "VIRTUAL_PORT=38232"
          - "LETSENCRYPT_HOST=domain name"
          - "[email protected]"
        
        
        expose:
          - "38232"
      
  web1:
    image: nginx:latest
    restart: always
    expose:
      - "80"
      
    volumes:
      - /opt/trojan/nginx/html:/usr/share/nginx/html:ro
      
     
    environment:
      - VIRTUAL_HOST=domain name
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=domain name
      - [email protected]
     
 
      
networks:
  default:
    external:
      name: proxy_nginx-proxy

the content of trojan-go config.conf is shown below:

{
  "run_type": "server",
  "local_addr": "0.0.0.0",
  "local_port": 38232,
  "remote_addr": "trojan_web",
  "remote_port": 80,
  "log_level": 1,
  
  "password": [
       "mypasswd"
  ],
 
  
  "ssl": {
    "verify": true,
    "verify_hostname": true,
    "cert": "/opt/crt/domain name.crt",
    "key": "/opt/crt/domain name.key",
    "sni":"domain name"
    },
"router":{
"enabled": true,
"block": [
"geoip:private"
]
}
}

(ps:I confirm that the trojan-go service and the web container are on the same intranet and can communicate with each other)

1

There are 1 best solutions below

0
sa-mustafa On

Although the question is old, I think it's worth answering. There are two problems here: one with the docker compose script, the other with the trojan-go itself. The first problem is

"remote_addr": "trojan_web"

should be changed to

"remote_addr": "web1"

as the error correctly points out 'connection refused', because nothing is there listening! The other problem is trojan-go may have difficulty redirecting correctly. Turn log level to debug and check if the redirection happens correctly between trojan-go and nginx.