I'm getting the following error when i hit my server Url
my request: curl 'http://52.66.253.182/osrm/nearest?loc=73.920239,18.5649413'
{"message":"URL string malformed close to position 1: \"\/\/ne\"","code":"InvalidUrl"}
I think it's something related to my nginx server conf file
here's my conf file code :
upstream osrm {
server 0.0.0.0:5000;
}
server {
listen 80;
server_name 52.66.253.182;
location /osrm {
proxy_pass http://osrm/;
proxy_set_header Host $http_host;
}
}
Browser resposne
I'm able to run it on localhost .
my Request : curl 'http://localhost:5000/route/v1/driving/73.9635837,18.5330435;74.0200603,18.5454127'
Response : {"code":"Ok","routes":[{"geometry":"mkbpByambM|e#xDIul#tKkf#pJeNGwTmJ{NuHoBXkIrBkGoIcIsD\\gD{Bk#aEfBsAoFyJ}[oDgc#yI_oAgMdFoX|Eyj#v#}}#","legs":[{"steps":[],"distance":9577.3,"duration":883.7,"summary":"","weight":883.7}],"distance":9577.3,"duration":883.7,"weight_name":"routability","weight":883.7}],"waypoints":[{"hint":"Ji2DgCktg4AAAAAAJgAAAAAAAADQAwAAAAAAABNd1EEAAAAAvawpRAAAAAAmAAAAAAAAANADAAD4AgAAwJloBMnDGgFAmGgEtMoaAQAAjwsvU8Mk","name":"","location":[73.963968,18.531273]},{"hint":"dwQogM0IdYAAAAAANAAAAPgLAACOBAAAAAAAAMSZD0KaBQVFm1qERAAAAAA0AAAA-AsAAI4EAAD4AgAA8HRpBMUIGwHcdGkEBfsaASkAnwUvU8Mk","name":"","location":[74.02008,18.548933]}]}
Related
I am doing load balancing with Nginx. Here is my config
upstream web_backend {
least_conn;
server localhost:8001 max_fails=3 fail_timeout=60s;
server localhost:8002 max_fails=3 fail_timeout=60s;
}
server {
listen 8545;
server_name _;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_backend;
}
}
server {
listen 8001;
server_name localhost;
location / {
proxy_pass https://some_other_url/v3/cxnmcdinwrtyf93vcwdiyfx8q6xqwxv9qg7c93fgcb;
}
}
server {
listen 8002;
server_name localhost;
location / {
proxy_pass 'https://chipdunk-dude:gorgeous-serpents-clubbed-orphans#nd-657-555-555-777.dogify.com';
}
}
as you can see the url at port 8002 is weird (dont even know what this kind of urls are called)
because it has ":" in the url, Nginx gives me this error
nginx: [emerg] invalid port in upstream "chipdunk-dude:gorgeous-serpents-clubbed-orphans#nd-657-555-555-777.dogify.com" in /etc/nginx/sites-enabled/default:60
The url at port 8001 works fine.
Everything before the # is userinfo which should be encoded by the browser and included as a separate request header according to RFC 7617.
Nginx is not a browser and cannot do it for you.
You could probably convert that into Base64 and use a proxy_set_header to set the Authorization header.
For example:
proxy_set_header Authorization "Basic Y2hpcGR1bmstZHVkZTpnb3JnZW91cy1zZXJwZW50cy1jbHViYmVkLW9ycGhhbnM=";
proxy_pass https://nd-657...;
I am having a problem with my Nginx configuration.
I have an Nginx server(A) that adds custom headers and then that proxy_passes to another server(B) which then proxy passes to my flask app(C) that reads the headers. If I go from A -> C the flask app can read the headers that are set but if I go through B (A -> B -> C) the headers seem to be removed.
Config
events {
worker_connections 512;
}
http {
# Server B
server {
listen 127.0.0.1:5001;
server_name 127.0.0.1;
location / {
proxy_pass http://127.0.0.1:5000;
}
}
# Server A
server {
listen 4999;
server_name domain.com;
location / {
proxy_pass http://127.0.0.1:5001;
proxy_set_header X-Forwarded-User 'username';
}
}
}
Flask app running on 127.0.0.1:5000
If I change the server A config to proxy_pass http://127.0.0.1:5000 then the Flask app can see the X-Forwarded-User but if I go through server B the headers are "lost"
I am not sure what I am doing wrong. Any suggestions?
Thanks
I can not reproduce the issue, sending the custom header X-custom-header: custom in my netcat server i get:
nc -l -vvv -p 5000
Listening on [0.0.0.0] (family 0, port 5000)
Connection from localhost 41368 received!
GET / HTTP/1.0
Host: 127.0.0.1:5000
Connection: close
X-Forwarded-User: username
User-Agent: curl/7.58.0
Accept: */*
X-custom-header: custom
(see? the X-custom-header is on the last line)
when i run this curl command:
curl -H "X-custom-header: custom" http://127.0.0.1:4999/
against an nginx server running this exact config:
events {
worker_connections 512;
}
http {
# Server B
server {
listen 127.0.0.1:5001;
server_name 127.0.0.1;
location / {
proxy_pass http://127.0.0.1:5000;
}
}
# Server A
server {
listen 4999;
server_name domain.com;
location / {
proxy_pass http://127.0.0.1:5001;
proxy_set_header X-Forwarded-User 'username';
}
}
}
thus i can only assume that the problem is in the part of your config that you isn't showing us. (you said it yourself, it's not the real config you're showing us, but a replica. specifically, a replica that isn't showing the problem)
thus i have voted to close this question as "can not reproduce" - at least i can't.
Nginx forwards call in a wrong way when configured with upstream!
Not working
upstream search {
server some.server.com;
}
server {
listen 80;
location / {
proxy_pass http://search;
}
}
Working good
upstream search {
server some.server.com;
}
server {
listen 80;
location / {
proxy_pass http://some.server.com;
}
}
When configured with upstream - target server returns "404 - Resource not found"
What do I do wrong?
Problem was in 'HOST' header
in case of upstream header 'HOST' is set to search.
To fix that you need to replace 'HOST' header in request
location / {
proxy_set_header Host some.server.com;
proxy_pass http://search;
}
I done congfiguration in nginx for redirection and it works successfully.
But in that i want load balancing :-
for that i already create load-balancer.conf as well as give server name into that file like :-
upstream backend {
# ip_hash;
server 1.2.3.4;
server 5.6.7.8;
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}
In both instances i did same configuration
and it default uses round-robin algorithm so in that request transfer via one pc to another pc.....
but it were not working
can any one suggest me anything that secong request going to another server 5.6.7.8
so i can check load balancing.
Thankyou so much.
Create a log file for upstream to check request is going to which server
http {
log_format upstreamlog '$server_name to: $upstream_addr {$request} '
'upstream_response_time $upstream_response_time'
' request_time $request_time';
upstream backend {
# ip_hash;
server 1.2.3.4;
server 5.6.7.8;
}
server {
listen 80;
access_log /var/log/nginx/nginx-access.log upstreamlog;
location / {
proxy_pass http://backend;
}
}
and then check your log file
sudo cat /var/log/nginx/nginx-access.log;
you will see log like
to: 5.6.7.8:80 {GET /sites/default/files/abc.png HTTP/1.1} upstream_response_time 0.171 request_time 0.171
I have a nginx.conf which basically looks like (unnecessary parts omitted):
upstream app {
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
location #app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
}
I want to configure nginx so that the value of a specific header is used to rewrite the url being passed to the upstream.
For example, let's assume that I have a request to /test with the header Accept: application/vnd.demo.v1+json. I'd like it to be redirected to the upstream URL /v1/test, i.e. basically the upstream app will receive the request /v1/test without the header.
Similarly, the request to /test and the header Accept: application/vnd.demo.v2+json should be redirected to the upstream URL /v2/test.
Is this feasible? I've looked into the IfIsEvil nginx module, but the many warnings in there made me hesitant to use it.
Thanks,
r.
edit
In case there's no match, I'd like to return a 412 Precondition Failed immediately from nginx.
If Accept header does not contain required header return error.
map $http_accept $version {
default "";
"~application/vnd\.demo\.v2\+json" "v2";
"~application/vnd\.demo\.v1\+json" "v1";
}
server {
location #app {
if ($version = "") {
return 412;
}
...;
proxy_pass http://app/$version$uri$is_args$args;
}
}