2

Trying to do a simple proxy from sub.domain.com/link1 to another server 10.1.1.1:8080/someotherlink1.

This is what my server context looks like: (I modified the default nginx.conf)

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  sub.domain.com;
    root         /;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location /link1 {      
        proxy_pass http://10.1.1.1:8080/link2
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

`

but visiting a webpage is just loading the nginx 502 bad gateway page.

Error in the log is:

2017/03/15 22:04:27 [crit] 8647#0: *11 connect() to 10.1.1.1:8080 failed (13: Permission denied) while connecting to upstream, client: 112.xxx.xxx.xxx, server: sub.domain.com, request: "GET /link1/ HTTP/1.1", upstream: "http://10.1.1.1.1:8080/link2/", host: "sub.domain.com"

What's a bit strange looking is the GET /link1/ - as this this should not be the link in the final upstream URL - it should not be trying to get this link.

What am I doing wrong?

0

You do not pass the URI on the proxy_pass directive, you need to first rewrite or redirect then pass it to the proxy, for example:

location /link1 {
  return 301 $scheme://$http_host/link2$args;
}

location /link2 {
  proxy_pass http://10.1.1.1:8080;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.