Can I proxy_pass to a variable?

config:
server {
listen [::]:80 default;
server_name _ ;
server_name_in_redirect off;
resolver 74.207.241.5;

    access_log  off;

    auth_basic      "Private proxy";
    auth_basic_user_file /etc/nginx/auth_basic_user;

    location /{
            proxy_pass http://$http_host;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For 

$proxy_add_x_forwarded_for;
}
}

error.log:
2010/05/10 11:02:25 [error] 31032#0: *45 zero length URI to proxy,
client: ::ffff:124.205.200.99, server: _, request: “GET
http://www.whatismyip.com/ HTTP/1.1”, host: “www.whatismyip.com

If a specify an IP address or a domain name in proxy_pass, it worked.
I use $http_host, it doesnt work. How can I do?

/usr/sbin/nginx -V

nginx version: nginx/0.7.64
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock
–http-log-path=/var/log/nginx/access.log
–http-client-body-temp-path=/var/lib/nginx/body
–http-proxy-temp-path=/var/lib/nginx/proxy
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug
–with-http_stub_status_module --with-http_flv_module
–with-http_ssl_module --with-http_dav_module
–with-http_gzip_static_module --with-mail --with-mail_ssl_module
–with-ipv6
–add-module=/tmp/buildd/nginx-0.7.64/modules/nginx-upstream-fair


Ren Xiaolei

On Mon, May 10, 2010 at 7:54 AM, 任晓磊 [email protected] wrote:

    auth_basic_user_file /etc/nginx/auth_basic_user;

    location /{

  • Â Â Â Â Â Â Â Â proxy_pass http://$http_host;
  •            proxy_pass http://$http_host$uri;
    

–http-proxy-temp-path=/var/lib/nginx/proxy
nginx mailing list
[email protected]
nginx Info Page


Boris D…

On Mon, May 10, 2010 at 11:54:45AM +0800, 任晓磊 wrote:

    auth_basic_user_file /etc/nginx/auth_basic_user;

client: ::ffff:124.205.200.99, server: _, request: “GET
http://www.whatismyip.com/ HTTP/1.1”, host: “www.whatismyip.com

If a specify an IP address or a domain name in proxy_pass, it worked.
I use $http_host, it doesnt work. How can I do?

/usr/sbin/nginx -V

nginx version: nginx/0.7.64

You have to write:

 proxy_pass http://$http_host$request_uri;

Since 0.8.25 and 0.7.65, you may write:

 proxy_pass http://$http_host;


Igor S.
http://sysoev.ru/en/

On Mon, May 10, 2010 at 2:07 PM, Igor S. [email protected] wrote:

You have to write:

  proxy_pass http://$http_host$request_uri;

Since 0.8.25 and 0.7.65, you may write:

  proxy_pass http://$http_host;

But, why didn’t I need to specify $request_uri when proxy_pass to a
literal value?


Ren Xiaolei

On Mon, May 10, 2010 at 04:29:46PM +0800, 任晓磊 wrote:

literal value?
For historical reasons.
There are two ways to map URI to a resource: root and alias:

 location /dir1/ {
     root  /path/to;
 }

 location /dir2/ {
     alias  /path/to/dir3/;
 }

The variables support has appeared eventually:

 location / {
     root  /path/$host;
 }

 location ~ ^/~(?<user>[^/]+)(?<path>.*)$ {
     alias  /homes/$user/$path;
 }

In proxy_pass the root way is:

 location /dir1/ {
     proxy_pass  http://host;
 }

The alias way is:

 location /dir2/ {
     proxy_pass  http://host/dir3/;
 }

The proxy_pass variables support has appeared to support proxying to a
full
URL only as in static alias. Then the root way has been added.


Igor S.
http://sysoev.ru/en/

On Mon, May 10, 2010 at 4:52 PM, Igor S. [email protected] wrote:

The proxy_pass variables support has appeared to support proxying to a full
URL only as in static alias. Then the root way has been added.
Thank you for explaination.


Ren Xiaolei