Hello every body. Hope all of you are healthy.
Playing around with Docker containers and web servers, I am facing a “challenge”.
I run Apache as web server in CentOS 8.
I have already set up many virtual hosts and they are running smoothly.
Additionally I have made entries with imaginary domain names in local /etc/hosts file and they are serving normally thanks to Apache names based virtual hosts.
Now I want to serve Docker containers instead of simple html pages.
All of them are accessible with Docker command -p 8080:80 and more over are accessible with imaginary domain names only if I add port on my web server. For example:
Nextcloud.net :8080.
Now I want to access them with our adding the port at the end.
I found the below code in git hub but is not working for me.
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www
ServerName docker.example.com
ErrorLog logs/docker.example.com_error.log
CustomLog logs/docker.example.com_access.log combined
ProxyPreserveHost On
ProxyRequests off
<Location />
ProxyPass http://localhost:9000/
ProxyPassReverse http://localhost:9000/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
any help would be appreciated.
I basically found the same info as you: Simple Apache reverse proxy example | JamesCoyle.net Limited
But it’s really hard to troubleshoot if you only post the generic example, and not a concrete example of your config. Also, it would be nice to know exactly what is not working.
Could you post an example of the config file exactly as it would be for you (for an imaginary or real service) and also be specific about what errors you get etc. (log output for instance)?
Also please list ‘docker ps’ so we can see your forwarded ports in docker.
This is how I wrote the code inside /etc/http/sites-available. (one of the variations that I have tried already)
<VirtualHost nextcloud1.net>
DocumentRoot /var/www/html
ServerName nextcloud1.net
ErrorLog logs/nextcloud1.net_error.log
CustomLog logs/nextcloud1.net_access.log combined
ProxyPreserveHost On
ProxyRequests off
<Location />
ProxyPass http://localhost:8080/
ProxyPass http://localhost:8080/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
I’m receiving this error:
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
If I type in browser
nextcloud1.net:8080
page is serving normally. (/etc/hosts entry include nextcloud1.net)
Without being entirely sure, I would think reverse proxy works only on subdomains, so it should be nextcloud.home.net (or something similar).
I’m not aware how reverse proxy works “directly” on main domains (nextcloud1.net).
What happens if you put the server’s IP address instead of localhost in the proxypass?
Besides, I’m not familiar with Apache, so this is completely random troubleshooting for my part. 
I’m not sure if this is a typo on here or not but you don’t have the ProxyPassReverse line on your location settings. I’m not even a little familiar with reverse proxy in apache so I’m not sure if this was intentional or not.
Good catch - of course one of the lines need to be ProxyPassReverse.