Comments (18)
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.
@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.
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.
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.
I am guessing this is just me not understanding docker properly. I have only been playing with it for a week now.
from haproxy.
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),
from haproxy.
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.
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.
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.
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.
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.
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.
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.
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 admindefaults
mode httpfrontend 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.
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.
This is an haproxy issue although the base image may want to be update to use the -db flag.
from haproxy.
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.
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)
- I'm using this: HOT 2
- Release haproxy image with lua version >= 5.4.2 HOT 2
- High CPU usage with 2.6.3 (latest) docker image HOT 4
- Cannot open configuration file /usr/local/etc/haproxy/haproxy.cfg: No such file or directory HOT 6
- Memory exhaustion using haproxy image HOT 3
- OOM killed using haproxy image HOT 5
- core dumps not being stored HOT 7
- Use /var/run/docker.sock as backend server HOT 2
- Why build from source code? HOT 2
- [ALERT] (1) : [haproxy.main()] Cannot create pidfile /var/run/haproxy.pid HOT 2
- If you have a new enough kernel (`4.11`), then adding `--sysctl net.ipv4.ip_unprivileged_port_start=0` to the `docker run` should allow it to use "privileged" ports (https://github.com/moby/moby/issues/8460). HOT 1
- CVE-2023-25725 HOT 6
- How to deal with "Failed to drop supplementary groups"? HOT 2
- Vulnerable component detection issue HOT 3
- "ltime" converter does not reflect container timezone HOT 4
- Haproxy not reloading config in docker HOT 1
- Crtitical/high vulnerabilities in all haproxy:bullseye images HOT 3
- HAProxy crashing on start, thread 2 is about to kill the process. HOT 11
- Images contain `*-dev` packages that are used to build HAProxy but which are useless at runtime
- Use multi-stage build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from haproxy.