Home > OS >  What is the difference between 'proxy_pass url' and 'proxy_pass upstream' in Ngi
What is the difference between 'proxy_pass url' and 'proxy_pass upstream' in Ngi

Time:08-18

Ex1)

    upstream uptest {
        server <some_lambda_id>.lambda-url.ap-northeast-2.on.aws:443;
        keepalive 100;
    }

    server {
        listen 80;

        #access_log off;
        access_log  /var/log/nginx/uptest_acc.log  main;
        error_log   /var/log/nginx/uptest_err.log error;

        server_name  <test_domain>;

        location / {
            proxy_pass https://uptest;
        }
    }

Ex1 is not work (403 forbidden and body response : {"Message":null})

Ex2)

    server {
        listen 80;

        #access_log off;
        access_log  /var/log/nginx/uptest_acc.log  main;
        error_log   /var/log/nginx/uptest_err.log error;

        server_name  <test_domain>;

        location / {
            proxy_pass https://<some_lambda_id>.lambda-url.ap-northeast-2.on.aws; 
        }
    }

Ex2 is work

What is the difference between 'proxy_pass url' and 'proxy_pass upstream' in Nginx ? How to fix 'Ex1' code?

Thanks for your time. Regards

CodePudding user response:

By default, proxy_pass sets two headers to default values, one of which is:

proxy_set_header Host $proxy_host;

See this document for details.

The value of $proxy_host is taken from the proxy_pass statement and not the upstream server statement.

So, the main difference will be the value of the Host header in the upstream request. In your upstream example, it will be set to uptest instead of the correct host name of the upstream server.

  • Related