ShadowsocksR-Live / overtls

A simple proxy tunnel, minimalist tool for bypassing the GFW.
MIT License
262 stars 42 forks source link

How to use Caddy to replace nginx #65

Closed chenxudong2020 closed 1 month ago

chenxudong2020 commented 1 month ago

How to use Caddy instead of nginx, it can automatically apply for certificates ,Can you help me?

ssrlive commented 1 month ago

I try to write a Caddyfile but it not works. can you resolve it?

mysite.com:443 {
    tls a@gmail.com
    encode gzip

    handle_path /mypathYWiWL* {
        reverse_proxy 127.0.0.1:12948
    }
    handle {
        reverse_proxy https://www.gov.cn {
            trusted_proxies 0.0.0.0/0
            header_up Host {upstream_hostport}
        }
    }
}

error looks like: Response { status: 200, version: HTTP/1.1, headers: {"alt-svc": "h3=\":443\"; ma=2592000", "server": "Caddy", "date": "Sun, 22 Sep 2024 08:40:23 GMT", "content-length": "0"}, body: None }

~# caddy -v
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=

the settings in nginx likes

        location /mypathWL/ {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:12948;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
        }
ssrlive commented 1 month ago

And this settings not work also:

fspaceinc.com:443 {
    tls s@gmail.com
    encode gzip

    handle_path /mypathWiWL/* {
        reverse_proxy http://127.0.0.1:12948 {
            header_up Host {host}
            header_up X-Real-IP {remote}
            header_up X-Forwarded-For {remote}
            header_up X-Forwarded-Proto {scheme}
            header_up Upgrade {upstream_upgrade}
            header_up Connection {upstream_connection}
        }
    }

    handle {
        reverse_proxy https://www.gov.cn {
            trusted_proxies 0.0.0.0/0
            header_up Host {upstream_hostport}
        }
    }
}
chenxudong2020 commented 1 month ago

I tried the key point that nginx supports websocket configuration and converted it to caddy, but found it to be an old error. I am not familiar with caddy and only want to use its automatic certificate application to configure multi domain sharing 443. However, I found that it does not work and can only wait for someone familiar with it to improve. Recently, I found that the previous nginx configuration also reported an error, and I am not sure if it is due to overtls upgrade

ssrlive commented 1 month ago

Now overtls can work with Caddy, the Caddyfile likes

mysite.com:443 {
    tls s@gmail.com
    encode gzip

    reverse_proxy /mypathWiWL/* 127.0.0.1:12456

    reverse_proxy https://www.sohu.com {
        trusted_proxies 0.0.0.0/0
        header_up Host {upstream_hostport}
    }
}

Hope somebody can write an installation script.

Caddy installation script

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
ssrlive commented 1 month ago

Caddy not support using IP as host name. so you must provide a domain name for your config file.

image

https://caddy.community/t/reverse-proxy-to-websocket-server-failed/25756/8

ssrlive commented 1 month ago

image

chenxudong2020 commented 1 month ago

Do you mean to change 127.0.0.1 to a domain name?

ssrlive commented 1 month ago

image

ssrlive commented 1 month ago

https://github.com/ShadowsocksR-Live/overtls?tab=readme-ov-file#installation-script-with-caddy

chenxudong2020 commented 1 month ago

https://github.com/ShadowsocksR-Live/overtls?tab=readme-ov-file#installation-script-with-caddy

https://github.com/ShadowsocksR-Live/overtls?tab=readme-ov-file#installation-script-with-caddy

I used a one click installation script and looked at the configuration file. It's basically the same as mine, except for tunnel_math. I have multiple others that are no different, but I still reported an error using Overtls win image

ssrlive commented 1 month ago

Because the overtls.dll file shiped by ssrwin does not use the dll included in the latest 0.2.37 version.

chenxudong2020 commented 1 month ago

I replaced this DLL file and it can be used now, but it still reports authentication failure because the locally launched one does not have authentication, which may be due to authentication information before the browser cache

chenxudong2020 commented 1 month ago

If you have time to modify SSRWin, Docker can be migrated from nginx to Caddy later

ssrlive commented 1 month ago

ssrwin latest release have contained overtls.dll of 0.2.27 version.