Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

Why the nginx forgets the base url and uses only $request_uri?

I would like to proxy the requests. The address it should proxy is base url + whatever comes after it.

So the base url is https://10.10.10.10:8080 and if I send a request to http://localhost:9000/api/user then it should be redirected to https://10.10.10.10:8080/api/user. Can't achieve it.

So I have the following settings:

server {
    listen 9000;
    server_name localhost;
    
    keepalive_timeout   70;
    
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass          https://10.10.10.10:8080/$request_uri;
    } 
}

And I get this as log:

127.0.0.1 - - [06/Jan/2021:08:27:02 +0100] "GET /api/user HTTP/1.1" 401 0 "-" "Java/1.8.0_221"

Seems like it forgets to add the ip address at the start...

Can anyone help me out?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...