Reverse Proxy redirecting from the source to where I intend to proxy

1. The problem I’m having:

I want to Reverse Proxy from this site : https://new.uservideo.xyz but it keep redirecting to proxy source (https://new.uservideo.xyz).

2. Error messages and/or full log output:

when i tried to access :8081 it redirected to source proxy

* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET / HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.88.1
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Cf-Cache-Status: DYNAMIC
< Cf-Ray: 7f70f384a8ae4c23-SIN
< Content-Type: text/html; charset=UTF-8
< Date: Tue, 15 Aug 2023 11:03:29 GMT
< Location: https://new.uservideo.xyz/
< Nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< Portzilla-Error: false
< Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=mRjWpK%2BybJJKT5lD6u9K7GBUoLGTLhytjUAGCd4mHFHC9KBhKWH%2FkJkayU0gapXXR0XgPa8%2BRum0vcx0EqnFUg3CCP3%2BBR7baLOSRrypT0HoMOWEyKMs4u2miQQfmsVYl6fuvPO3bQg%3D"}],"group":"cf-nel","max_age":604800}
< Server: Caddy
< Server: cloudflare
< Vary: Accept-Encoding
< X-Litespeed-Cache: miss
< X-Litespeed-Cache-Control: public,max-age=604800
< X-Litespeed-Tag: 30f_HTTP.200,30f_HTTP.301,30f_home,30f_URL.6666cd76f96956469e7be39d750cc7d9,30f_F,30f_
< X-Redirect-By: WordPress
< Content-Length: 0
<
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host localhost left intact

Here is debug log form caddy

{"level":"info","ts":1692097384.7690356,"msg":"using provided configuration","config_file":"./Caddyfile","config_adapter":""}
{"level":"warn","ts":1692097384.7923717,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"./Caddyfile","line":3}
{"level":"info","ts":1692097384.8111749,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1692097384.8138287,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0006d8880"}
{"level":"debug","ts":1692097384.8160114,"logger":"http.auto_https","msg":"adjusted config","tls":{"automation":{"policies":[{}]}},"http":{"servers":{"srv0":{"listen":[":8081"],"routes":[{"handle":[{"handler":"reverse_proxy","headers":{"request":{"set":{"Accept-Encoding":["identity"],"Host":["{http.reverse_proxy.upstream.hostport}"]}}},"transport":{"protocol":"http","tls":{}},"upstreams":[{"dial":"new.uservideo.xyz:443"}]}]}],"automatic_https":{}}}}}
{"level":"info","ts":1692097384.8527768,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:C:\\Users\\U53R\\AppData\\Roaming\\Caddy"}
{"level":"info","ts":1692097384.8538337,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"debug","ts":1692097384.8538337,"logger":"http","msg":"starting server loop","address":"[::]:8081","tls":false,"http3":false}
{"level":"info","ts":1692097384.8555703,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1692097384.8566542,"msg":"autosaved config (load with --resume flag)","file":"C:\\Users\\U53R\\AppData\\Roaming\\Caddy\\autosave.json"}
{"level":"info","ts":1692097384.8566542,"msg":"serving initial configuration"}
{"level":"debug","ts":1692097408.6855216,"logger":"http.handlers.reverse_proxy","msg":"selected upstream","dial":"new.uservideo.xyz:443","total_upstreams":1}
{"level":"debug","ts":1692097409.388124,"logger":"http.handlers.reverse_proxy","msg":"upstream roundtrip","upstream":"new.uservideo.xyz:443","duration":0.6969309,"request":{"remote_ip":"127.0.0.1","remote_port":"55133","client_ip":"127.0.0.1","proto":"HTTP/1.1","method":"GET","host":"new.uservideo.xyz:443","uri":"/","headers":{"Accept-Encoding":["identity"],"User-Agent":["curl/7.88.1"],"Accept":["*/*"],"X-Forwarded-For":["127.0.0.1"],"X-Forwarded-Proto":["http"],"X-Forwarded-Host":["localhost:8081"]}},"headers":{"X-Redirect-By":["WordPress"],"Nel":["{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}"],"Location":["https://new.uservideo.xyz/"],"Cf-Cache-Status":["DYNAMIC"],"X-Litespeed-Cache":["miss"],"X-Litespeed-Cache-Control":["public,max-age=604800"],"Date":["Tue, 15 Aug 2023 11:03:29 GMT"],"Cf-Ray":["7f70f384a8ae4c23-SIN"],"X-Litespeed-Tag":["30f_HTTP.200,30f_HTTP.301,30f_home,30f_URL.6666cd76f96956469e7be39d750cc7d9,30f_F,30f_"],"Report-To":["{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=mRjWpK%2BybJJKT5lD6u9K7GBUoLGTLhytjUAGCd4mHFHC9KBhKWH%2FkJkayU0gapXXR0XgPa8%2BRum0vcx0EqnFUg3CCP3%2BBR7baLOSRrypT0HoMOWEyKMs4u2miQQfmsVYl6fuvPO3bQg%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}"],"Content-Type":["text/html; charset=UTF-8"],"Alt-Svc":["h3=\":443\"; ma=86400"],"Portzilla-Error":["false"],"Vary":["Accept-Encoding"],"Server":["cloudflare"]},"status":301}

3. Caddy version:

v2.7.3 h1:eMCNjOyMgB5A1KgOzT2dXKR4I0Va+YHCJYC8HHu+DP0=

4. How I installed and ran Caddy:

i downloaded windows binary from Download Caddy

a. System environment:

Windows

b. Command:

./caddy.exe run --config ./Caddyfile

c. Service/unit/compose file:

d. My complete Caddy config:

{
	order replace after encode
}

:8081 {
    reverse_proxy * https://new.uservideo.xyz {
        header_up Host {upstream_hostport}
		header_up Accept-Encoding identity
    }
}

5. Links to relevant resources:

Your upstream is probably seeing X-Forwarded-Proto: http and redirecting to HTTPS because of that.

You could add header_up X-Forwarded-Proto https to override that.

thank you for looking onto this. i’ve added X-Forward-Proto but it still redirecting to upstream.
Caddy Config

:8082 {
    reverse_proxy * https://new.uservideo.xyz {
        header_up Host {upstream_hostport}
		header_up Accept-Encoding identity
		header_up X-Forwarded-Proto https
    }
}

curl example & respond

$ curl -vk 'http://localhost:8082'
*   Trying 127.0.0.1:8082...
* Connected to localhost (127.0.0.1) port 8082 (#0)
> GET / HTTP/1.1
> Host: localhost:8082
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Cf-Cache-Status: DYNAMIC
< Cf-Ray: 7f770f2ae831a066-SIN
< Content-Type: text/html; charset=UTF-8
< Date: Wed, 16 Aug 2023 04:50:56 GMT
< Location: https://new.uservideo.xyz/
< Nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< Portzilla-Error: false
< Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=v8IHq%2FZ2V%2FtRcEnEjzErlKUcFAOWISfPXZOb2QL1PonKU6SuhRVxYN0F5VQRjb4qGdmMKAG6OY3%2B9rQ%2B4fMs0vL6FEtscxcTc3pAwcRANtTgShNGOCJxEv3AUnwk%2FHcDPM4XVzD1IJ8%3D"}],"group":"cf-nel","max_age":604800}
< Server: Caddy
< Server: cloudflare
< Vary: Accept-Encoding
< X-Litespeed-Cache: miss
< X-Litespeed-Cache-Control: public,max-age=604800
< X-Litespeed-Tag: 30f_HTTP.200,30f_HTTP.301,30f_home,30f_URL.6666cd76f96956469e7be39d750cc7d9,30f_F,30f_
< X-Redirect-By: WordPress
< Content-Length: 0
<
* Connection #0 to host localhost left intact

caddy command & debug log

PS D:\rexy> .\caddy.exe run --config .\Caddyfile
2023/08/16 04:50:52.871 INFO    using provided configuration    {"config_file": ".\\Caddyfile", "config_adapter": ""}
2023/08/16 04:50:52.872 WARN    Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies    {"adapter": "caddyfile", "file": ".\\Caddyfile", "line": 8}
2023/08/16 04:50:52.878 INFO    admin   admin endpoint started  {"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2023/08/16 04:50:52.878 INFO    tls.cache.maintenance   started background certificate maintenance      {"cache": "0xc0003bef00"}
2023/08/16 04:50:52.878 DEBUG   http.auto_https adjusted config {"tls": {"automation":{"policies":[{}]}}, "http": {"servers":{"srv0":{"listen":[":8081"],"routes":[{"handle":[{"handler":"replace_response","replacements":[{"replace":"http://localhost:8081","search":"https://nanimex2.com"},{"replace":"localhost:8081","search":"nanimex2.com"},{"replace":"http://localhost:8082","search":"https://new.uservideo.xyz"},{"replace":"\u003cscript type='text/javascript' src='//pl20296809.highcpmrevenuegate.com/31/61/f5/3161f5c20606616be1015d31894ac689.js'\u003e\u003c/script\u003e","search_regexp":"(\u003cscript data-cfasync=\"false\" async type=\"text\\/javascript\" src=\".*?\"\u003e\u003c\\/script\u003e)"}]},{"handler":"reverse_proxy","headers":{"request":{"set":{"Accept-Encoding":["identity"],"Host":["{http.reverse_proxy.upstream.hostport}"]}}},"transport":{"protocol":"http","tls":{}},"upstreams":[{"dial":"nanimex2.com:443"}]}]}],"automatic_https":{}},"srv1":{"listen":[":8082"],"routes":[{"handle":[{"handler":"replace_response","replacements":[{"replace":"\u003cscript type='text/javascript' src='//pl20296809.highcpmrevenuegate.com/31/61/f5/3161f5c20606616be1015d31894ac689.js'\u003e\u003c/script\u003e","search_regexp":"(\u003cscript data-cfasync=\"false\" async type=\"text\\/javascript\" src=\".*?\"\u003e\u003c\\/script\u003e)"}]},{"handler":"reverse_proxy","headers":{"request":{"set":{"Accept-Encoding":["identity"],"Host":["{http.reverse_proxy.upstream.hostport}"],"X-Forwarded-Proto":["https"]}}},"transport":{"protocol":"http","tls":{}},"upstreams":[{"dial":"new.uservideo.xyz:443"}]}]}],"automatic_https":{}}}}}
2023/08/16 04:50:52.879 INFO    tls     cleaning storage unit   {"description": "FileStorage:C:\\Users\\Wahidin\\AppData\\Roaming\\Caddy"}
2023/08/16 04:50:52.879 INFO    tls     finished cleaning storage units
2023/08/16 04:50:52.879 DEBUG   http    starting server loop    {"address": "[::]:8081", "tls": false, "http3": false}
2023/08/16 04:50:52.879 INFO    http.log        server running  {"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2023/08/16 04:50:52.880 DEBUG   http    starting server loop    {"address": "[::]:8082", "tls": false, "http3": false}
2023/08/16 04:50:52.880 INFO    http.log        server running  {"name": "srv1", "protocols": ["h1", "h2", "h3"]}
2023/08/16 04:50:52.880 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\Wahidin\\AppData\\Roaming\\Caddy\\autosave.json"}
2023/08/16 04:50:52.880 INFO    serving initial configuration
2023/08/16 04:50:55.385 DEBUG   http.handlers.reverse_proxy     selected upstream       {"dial": "new.uservideo.xyz:443", "total_upstreams": 1}
2023/08/16 04:50:55.974 DEBUG   http.handlers.reverse_proxy     upstream roundtrip      {"upstream": "new.uservideo.xyz:443", "duration": 0.5805383, "request": {"remote_ip": "127.0.0.1", "remote_port": "50220", "client_ip": "127.0.0.1", "proto": "HTTP/1.1", "method": "GET", "host": "new.uservideo.xyz:443", "uri": "/", "headers": {"X-Forwarded-Host": ["localhost:8082"], "Accept": ["*/*"], "User-Agent": ["curl/8.1.2"], "X-Forwarded-For": ["127.0.0.1"], "Accept-Encoding": ["identity"], "X-Forwarded-Proto": ["https"]}}, "headers": {"Alt-Svc": ["h3=\":443\"; ma=86400"], "Content-Type": ["text/html; charset=UTF-8"], "Portzilla-Error": ["false"], "X-Litespeed-Cache": ["miss"], "X-Litespeed-Cache-Control": ["public,max-age=604800"], "Date": ["Wed, 16 Aug 2023 04:50:56 GMT"], "Vary": ["Accept-Encoding"], "Server": ["cloudflare"], "Cf-Ray": ["7f770f2ae831a066-SIN"], "Cf-Cache-Status": ["DYNAMIC"], "Report-To": ["{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=v8IHq%2FZ2V%2FtRcEnEjzErlKUcFAOWISfPXZOb2QL1PonKU6SuhRVxYN0F5VQRjb4qGdmMKAG6OY3%2B9rQ%2B4fMs0vL6FEtscxcTc3pAwcRANtTgShNGOCJxEv3AUnwk%2FHcDPM4XVzD1IJ8%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}"], "Location": ["https://new.uservideo.xyz/"], "X-Litespeed-Tag": ["30f_HTTP.200,30f_HTTP.301,30f_home,30f_URL.6666cd76f96956469e7be39d750cc7d9,30f_F,30f_"], "X-Redirect-By": ["WordPress"], "Nel": ["{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}"]}, "status": 301}

The redirect is coming from Wordpress, so ultimately you’ll need to dig into why it’s performing the redirect. You can likely look for X-Redirect-By in the code to track it down.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.