Nesting variables in Apache config - apache

I'm building a Docker-based Apache proxy, and I'd like the proxied port to be configurable.
I link the containers with --link ...:proxied, so Docker makes the environment variables PROXIED_PORT_80_TCP_ADDR and PROXIED_PORT_80_TCP_PORT. I used ProxyPass / "http://${PROXIED_PORT_80_TCP_ADDR}:${PROXIED_PORT_80_TCP_PORT}/" to reverse proxy to port 80.
I'd like the port to be configurable from the command line, when I start the container. I pass the variable as -e "PORT=...", and it is usable as ${PORT} in the Apache config.
I've tried to nest the variables, like ${PROXIED_PORT_${PORT}_TCP_ADDR} without success, and also using the Define plugin, but still no luck.

Related

Mount services into caddy with directories

I want to host a few services (currently cal/carddav, synthing and popfile) on my local pc and share them to the local network without having to care for ports. I am using Caddy as a reverse proxy.
So, I'd like localhost:5232 to be accessible as https://myhostname.local/radicale and similar mappings for the other services.
However sudo caddy reverse-proxy --from myhostname.local/radicale --to localhost:5232 gives reverse-proxy: paths are not allowed: myhostname.local/radicale.
What do I have to do?
The caddy reverse proxy command is very limited and doesn't work with paths. To use paths you would need to setup a caddyfile similar to the one below. You'll need to repeat the second line changing the path and port for each service.
Filename: caddyfile
myhostname.local
reverse_proxy /radicale localhost:5232
From now on start caddy with sudo caddy start

Using docker bridge network IP to access vhost in apache container

I'd like to understand how I'm able to access a domain configured in a vhost inside a docker container by providing an entry in my local /etc/hosts file with the docker bridge network IP.
I use docker-compose (v2)
Docker network bridge IP (by default): 172.17.0.1
I have an apache container running on 172.19.0.10
Vhost is simple like :
<VirtualHost *:80>
ServerName mywebsite.local
In my local /etc/hosts file, I have : 172.17.0.1 mywebsite.local
And it works... but how ?
Is Docker using the port to guess where to forward the traffic (from 172.17.0.1 to 172.19.0.10) ?
Can someone give me with some explanations and if possible documentation ?
Thanks.
At some point you had to start your container/docker with something like this:
docker run -d -p 1337:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
1337:80 means that localhost:1337 in your browser gets looked up on port 80, and therefore your apache-container.
Hopefully what you had in mind?!
Also see this or that.
You can try using
docker run -d --network=host <image> or in docker compose
network_mode: "host". Documentations on this can be found here.
Both of these put your container on top of the host network stacks.

Apache route subdomain to nginx on port?

I have a server running CentOS 7 that has an Apache web-server running on port 80. I am also using a common open-source Git project called GitLab, which uses the nginx web-server instead of Apache. I have configured GitLab's nginx to run on port 4444.
I have a subdomain "git.mydomain.com" that I would like to forward to "mydomain.com:4444" however I would like the URL to continue saying "git.mydomain.com".
I belived that I need to have an Apache VirtualHost file, however I'm not sure what to do.
Is this possible? If so, how can I do so?
Thanks
You would indeed need a git.mydomain.com VirtualHost with a proxy/reverse proxy directive. See https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

Run apache in both host machine and docker container on 80 port

I need to setup something like automated server setup using docker. Now server machine should support both docker or normal setups. So I need to setup apache web server on both docker container and host machine on 80 port. Like
Host Machine : application1.serverhost.com
Docker Machine : application2.serverdocker.com
But Docker will not utilize 80 port as it is already bind on host machine apache. While I am thinking of use reverse proxy on host machine with apache like
Proxy Setting -> 172.17.0.2:8080
while on browser connect to proxy application2.serverdocker.com on 80 port. IP -> 172.17.0.2 is docker container IP which I am thinking to get from docker inspect.
But if any other way to handle this in docker itself where I can ignore reverse proxy on host machine. And call both application1.serverhost.com and application2.serverdocker.com from browser without appending port.
EDIT : One big issue using reverse proxy is that whenever I need to add another docker on same server I need to add also proxy for that new IP too as that would also running docker apache on other port like 8081 than Host port:80 and first docker's port:8080. In other words lot of reverse proxy settings and ports in case of lot of docker instances.
If you are using a reverse proxy, (like an NGiNX), that means both your Apache servers must run on ports different from 80.
Only your NGiNX would run (on host directly for instance) on port 80, and would redirect to localhost_apache1:xxx and 172.17.0.2_apache2:yyy.
From the user perspective, both Apache would be seen "as if" they were running on port 80 themselves.

reverse proxy apache to localhost server

I've got a web app running on localhost:3000. I also have an apache server. I would like to reverse proxy the apache server so that requests to /mywebapp get forwarded to the server running on localhost:3000.
I currently have the following config at the bottom of my httpd.conf file, but I'm getting a server error when I try to access it:
ProxyPass /mywebapp http://localhost:3000
ProxyPassReverse /mywebapp http://localhost:3000
Edit - further details:
I'm running a jetty server with java -jar myapp.jar. I'd like to forward requests to an apache server listening on :80 to the jetty server.
I've got mod_proxy_http.so and mod_proxy.so enabled.
I can tell the server is running on localhost - it responds to curl with the appropriate http response. So I'm pretty sure the issue is with my apache setup, but I can't think what the problem would be.
Apache conf file in conf.d for reference: http://pastebin.com/vhXwjbQe
And I've got this in my httpd.conf:
Include conf.d/*.conf
It's hard to give a generic answer because every situation is different so here are some debugging questions to ask yourself:
if the protocol and port correct on the internal service, http and 3000.
Is the service actually listening for connections from localhost? is it running in a docker container etc that would require it to be listening on a different interface? You can check for this by looking at the output from mywebapp's logs and see if the request are making it through the proxy.
Do the paths on the internal service include the prefix that is being passed to Apache or does apache need to strip these off. if for instance mywebapp expects the path "/foo/bar" and apache's reverse proxy is sending it with the context path included "/mywebapp/foo/bar" then it will not match any path in mywebapp.