I have read the similar issue below but got a problem that will explain later in the question:
I have a config like below that proxy_pass to an upstream:
location /api2/ {
client_max_body_size 10m;
if ($scheme = 'https') {
proxy_pass https://api.example.com;
}
if ($scheme = 'http') {
proxy_pass http://api.example.com;
}
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
Here the api2 section is sent to the upstream. In the question I've linked above uses / at the end of proxy_pass to omit the api2 part. When I add the / at the end of proxy_pass I get the below error:
nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/sites-enabled/mysite:160
When I searched for the above error, the community says that you need to remove / in proxy_pass to solve the error.
So the question is why I'm getting api2 in the upstream? How should I remove api2 when proxying?
When I change the config to:
location /api2/ {
client_max_body_size 10m;
proxy_pass http://api.example.com/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
It works, but the https requests have problem sending request.
In the upstream section I get the below error:
GET //api2/my_endpoint HTTP/1.1" 404