Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup nginx/caddy before librespeed? #15

Open
jonirrings opened this issue Dec 2, 2024 · 3 comments · May be fixed by #16
Open

How to setup nginx/caddy before librespeed? #15

jonirrings opened this issue Dec 2, 2024 · 3 comments · May be fixed by #16

Comments

@jonirrings
Copy link

Hello, thanks to your great work.

I've setup a caddy before speedtest-rust, but it always gets 127.0.0.1 ip.
my caddy config is

http://s.o0x0o.cn, https://s.o0x0o.cn {
        root * /var/lib/librespeed-rs/assets
        file_server
        request_body {
                max_size 100MB
        }
        reverse_proxy /backend/* 127.0.0.1:18080
        tls {
                key_type p384
        }
}

I found find_remote_ip_addr always get peer_ip from connection
Is this supposed not to run behind a reverse-proxy?

@SudoDios
Copy link
Collaborator

SudoDios commented Dec 2, 2024

Hi @jonirrings
Your welcome ☺️.
I personally work with nginx and have little experience working with caddy.
But I think your config is not complete.
In reverse_proxy you need to pass the real ip to the service (X-Real-IP).
Like this :

http://s.o0x0o.cn, https://s.o0x0o.cn {
    reverse_proxy /backend/* 127.0.0.1:18080 {
        header_up X-Real-IP {remote}
    }
}

nginx :

server {
    	server_name s.o0x0o.cn;
    	
    	location / {
    		proxy_redirect          off;
        	proxy_pass_header       Server;
        	proxy_set_header        X-Real-IP $remote_addr;
        	proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_set_header        X-Scheme $scheme;
        	proxy_set_header        Host $http_host;
        	proxy_set_header        X-NginX-Proxy true;
        	proxy_pass              http://127.0.0.1:18080/;
    	}
    }

@jonirrings
Copy link
Author

jonirrings commented Dec 3, 2024

thanks for your quick response.
I read your great code, and found trust_addr_proxy is checking X-Real-IP header.

I setup caddy as your suggestion, but got 127.0.0.1.

Then I run your code locally behind a nginx and a caddy.
guess what I found.

Nginx will set X-Real-IP as is;
Caddy will set X-Real-IP as X-Real-Ip.🤣

Caddy canonicalizes header fields Link

After add serveral rows code to check X-Real-Ip, librespeed-rs return the expected address.

any solution for this situation?

Edited
PS: caddy reverse could use header_up X-Real-IP {remote_host} for ip address only.

@SudoDios SudoDios reopened this Dec 3, 2024
@SudoDios
Copy link
Collaborator

SudoDios commented Dec 3, 2024

How interesting and strange 😂.
Characteristic solution.
Can you fix it in a PR ?
i want contribution to increase

@jonirrings jonirrings linked a pull request Dec 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants