Giter Site home page Giter Site logo

Comments (18)

RedbackThomson avatar RedbackThomson commented on May 30, 2024 3

For historical purposes:
@michaeljs1990 needed to put his environment variables within double quotations marks in order for them to be interpreted as such by haproxy, rather than string literals.

Therefore his config file should have been:

global
  stats socket /tmp/haproxy.sock mode 600 level admin

defaults
  mode http

frontend http-proxy
  bind "*:${PORT}"

from haproxy.

dlgoodchild avatar dlgoodchild commented on May 30, 2024 1

@devopsw18 your issue doesn't look like it has anything to do with haproxy, your describing an issue with using environment variables in your react application. Haproxy doesn't pass environment variables to whatever it proxies to. You should go back to investigating your issue from within the scope of your react project.
Good luck.

from haproxy.

yosifkit avatar yosifkit commented on May 30, 2024

How are you accessing the env? Is this inside the config file? The env command seems to return all the expected values. 😕

$ docker run -it --rm haproxy env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=85d49e8a739f
TERM=xterm
HAPROXY_MAJOR=1.5
HAPROXY_VERSION=1.5.14
HAPROXY_MD5=ad9d7262b96ba85a0f8c6acc6cb9edde
HOME=/root

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

When I run..

docker exec -it haproxy env

I have a different set of environment variables returned then when i enter the container though /bin/bash and run env. What cases this? I am setting environment variables in my docker-compose file that i would like to access in the cfg file. Is this possible?

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

I am guessing this is just me not understanding docker properly. I have only been playing with it for a week now.

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

So I rebuilt the container and ran the same command as above docker exec -it haproxy env and it outputs all the proper environment variables however I am not able to access them in the cfg file still. Since haproxy is run from the command line instead of as a service I believe it should have access to all of the same environment variables that i have when running that command.

I have tried using env(TEST), $TEST, and ${TEST} syntax to see if that mattered.

from haproxy.

yosifkit avatar yosifkit commented on May 30, 2024

Whatever process is started by docker (the CMD) uses the environment set up by docker (which includes any environment list when run through docker-compose). Maybe try docker-compose run my-haproxy bash and see that env shows the configured values from the compose yaml. I think that there are limited places that you can reference env vars in the haproxy config, but I am not that familiar with it.

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

I just tried that docker-compose command and ran env when logged in. It has all the environment variables I am looking for set however It seems to still not be setting it right in my config. This is my config file if it helps at all.

global
  stats socket /tmp/haproxy.sock mode 600 level admin

defaults
  mode http
  stats enable
  stats uri /haproxy_stats
  stats realm HAProxy\ Statistics
  stats auth username:password
  stats refresh 5s

frontend http-proxy
  bind *:80
  acl ser hdr(host) -i ${URL_1}
  acl pay hdr(host) -i ${URL_2}
  use_backend server if ser
  use_backend payments if pay
  default_backend server

backend server
   balance roundrobin
   server ser1 server:80 check

backend payments
  balance roundrobin
  server pay1 payments:3000 check

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

the one place i found working environment variables with haproxy was in this repo https://github.com/evanp/haproxy/blob/master/haproxy-start.sh which uses entrypoint.

from haproxy.

yosifkit avatar yosifkit commented on May 30, 2024

Haproxy does have access to the docker set environment variables; I'm just not sure that it will interpret them for any value in the config file. Does the exact config work outside of docker?

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

I have seen posts of people using environment variables with haproxy. Although i just tested it locally on a non docker machine and it does not work as well. Can't find anything in the docs about where you can or can't use them as well.. I'm at a loss. Guess it's back to writing sed scripts to config stuff.

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

http://serverfault.com/questions/693753/using-haproxy-environmental-variables-in-haproxy-cfg-not-working here is the post where someone was using it and apparently got it working eventually. But of course they don't bother to say how.

from haproxy.

normanjoyner avatar normanjoyner commented on May 30, 2024

I got this working locally with the following:

Dockerfile

FROM haproxy:1.5.14
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

haproxy.cfg

global
  stats socket /tmp/haproxy.sock mode 600 level admin

defaults
  mode http

frontend http-proxy
  bind *:${PORT}

Docker run invocation
docker run -d -e PORT=1234 [image_id] haproxy -db -f /usr/local/etc/haproxy/haproxy.cfg

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

The -db seemed to be the trick! Thanks a ton norman.
On Sep 17, 2015 7:28 PM, "Norman Joyner" [email protected] wrote:

I got this working locally with the following:

Dockerfile

FROM haproxy:1.5.14COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

haproxy.cfg

global
stats socket /tmp/haproxy.sock mode 600 level admin

defaults
mode http

frontend http-proxy
bind *:${PORT}

Docker run invocation
docker run -d -e PORT=1234 [image_id] haproxy -db -f
/usr/local/etc/haproxy/haproxy.cfg


Reply to this email directly or view it on GitHub
#10 (comment)
.

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

Spoke a little too soon. This works for bind it seems but when i use it for setting the dns in ACL it does not... although it passes the config check. Have been looking all over to find a list of places environment variables are supported but the haproxy documentation although verbos is somewhat useless.

from haproxy.

michaeljs1990 avatar michaeljs1990 commented on May 30, 2024

This is an haproxy issue although the base image may want to be update to use the -db flag.

from haproxy.

dlgoodchild avatar dlgoodchild commented on May 30, 2024

I can confirm that I too had this issue and was simply resolved by enclosing the values using those environment variables with double quotes.
In my particular case I had:

frontend http-in
    bind *:80
    bind *:443 ssl crt ${SSL_PATH}${SSL_CERT}

...and to get this working I had to change to:

frontend http-in
    bind *:80
    bind *:443 ssl crt "${SSL_PATH}${SSL_CERT}"

from haproxy.

devopsw18 avatar devopsw18 commented on May 30, 2024

Hi @dlgoodchild,

I am using HAProxy version 2.8.5-1ppa1 and my backend app are running reactjs app but clients keep getting Invalid environment variables:
These variables are defined in the env_file for the reactjs and its 100% present but haproxy doest serve it some how. If I run the app not through haproxy then no problem.

Any idea what can be the issue or what I must set on the haproxy confi

from haproxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.