Running Traefik docker-proxy behind an apache server, redirecting/proxying some of the requests (or vice versa) - linux

I have a Traefik-2 docker-compose-setup for dev (and one similar for prod) with multiple docker-compose projects containing multiple dc-images, each can be reached locally like this: https://docker-app1.docker-doamin1.loc, incl. HTTPS/SSL-Certs; "dns" via /etc/hosts.
This works like a charm, when the traefik-container is running and the apache is not (port conflict otherwise)
I also have some projects that can be run directly on a local apache (on ubuntu/debian) with configurations in /etc/apache2/sites-available/ like this:
<VirtualHost *:80>
ServerName apache-app1.apache-domain1.loc
DocumentRoot /path-to/apache-app1.apache-domain1.loc/public
<Directory /path-to/apache-app1.apache-domain1.loc/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
Fallbackresource /index.php
</Directory>
DirectoryIndex index.php index.html
</VirtualHost>
But only if the apache is running and the docker-traefik container ist not, again because of the conflicting 80/443
I need (or want) both Versions to run simultaneously.
My idea was to run the docker-traefik container on different ports (20080/20443) and redirect/ProxyPass from apache to that docker-proxy-container (the other way round would be okay too)
I tried (e.g.)this:
<VirtualHost *:443>
ProxyPreserveHost On
ProxyRequests Off
ServerName docker-app1.docker-doamin1.loc
ServerAlias www.https://docker-app1.docker-doamin1.loc
ProxyPass / https://docker-app1.docker-doamin1.loc:20443/
ProxyPassReverse / https://docker-app1.docker-doamin1.loc:20443/
</VirtualHost>
having
127.0.1.1 docker-app1.docker-doamin1.loc
in my /etc/hosts.
But it does not work. And it would be better in each case to have wildcards redirected like this: *.docker-doamin1.loc.
For now all of this is for a local dev environment, so security is not that relevant.
It would be great, if someone had some hints here.

Related

Apache 2.4 Reverse proxy to Node Application on Docker

I have a dedicated server on Apache 2.4 and I made a node application which is running on a Docker container and listenning on the port 5847
So I am trying to configure my apache to make a reverse Proxy to http://my.url.com:5847 on a Debian 8 machine
When I made this, I have the start page of apache "It Works" but not my application. Of course, If I check http://my.url.com:5847 in my navigator, it works fine, but why my reverse Proxy doesn't work?
This is my my.url.com.conf apache config file :
<VirtualHost *:80>
ServerAdmin hello#my-url.com
ServerName my.url.com
ProxyPass "/" "http://my.url.com:5847/"
ProxyPassReverse "/" "http://my.url.com:5847/"
</VirtualHost>
So I'm quite desesperate, I also tried to add
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
I also tried with Required all granted, I tried with the <Location /> directive, with ProxyRequests Off and On too but nothing is working and I don't understand what is going wrong...
Can you help me please? What am I doing wrong?
This wks for me (apache 2.4, node.js runs in 192.168.32.35 on port 3003), on Debian 8
<VirtualHost feed.mydomain.net:3003>
ServerName feed.mydomain.net
ServerAdmin yves#mydomain.com
DocumentRoot /var/www/html
<Location />
ProxyPass http://192.168.32.35:3003/
ProxyPassReverse http://feed.mydomain.net:3003/
Order allow,deny
Allow from all
</Location>
LogLevel trace1 ssl:warn rewrite:trace1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Okay, so ... I think I found my error, I was writing an conf archive without .conf extension in sites-enabled and that's why apache wasn't taking my configuration... I re-made my configuration file in sties-enabled and then enabled it from apache with a2ensite my.url.com.conf and now it works...
Sorry for the bas question, nothing to do with reverse proxy!

Can linux host mutiple websites with one domain's different third domains?

I recently made some projects on raspberry pi with linux Debian Jessie, and I am interested in porting forward websites hosted on raspberry pi to a domain I owned.
From what I learned, it is possible to make each individual website on raspberry link with configured port according to apache , for example /home/pi/html/website01 -> port 11235 website02 -> 11236 so that I can browse the websites in private network. However, the domain I have is managed by godaddy, they provide the Chain without port, so that I can't redirect one of my third level domain(ex dashboard.domain.com to my dynamic dns hostname xx.dtdns.net with the port.
Is there any possible way or idea to get it work? I am lack of knowledge of nameserver, but I have an idea that using vpn or vps to map users to my private network instead of godaddy domain manager. I have alreay built the openvpn with cert and pptp vpn on my raspberrypi. Is it possible or what's next step?
Thanks, please give me some idea.
One solution would be to use Virtual Hosting in Apache on your Raspberry. Install Apache2 on PI with:
apt-get install apache2
Create a new conf file in /etc/apache2/sites-available or use an existing one. Add the ports for different site directories:
<VirtualHost *:11235>
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:11236>
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
and then set Apache tolisten on the ports in the /etc/apache2/ports.conf file:
Listen 11235
Listen 11236
Restart the Apache service. You should now be able to browse both ports using the same ip address. If your ip was 111.111.111.111 then w1 directory on 111.111.111.111:11235 and 111.111.111.111:11236.
If your domain is pointing to a IP, you can use different hostnames without making change to DNS. If you domain was mydomain.com, you could instead add new virtual host names with:
<VirtualHost *:80>
ServerName w1.mydomain.com
DocumentRoot /var/www/w1
<Directory /var/www/w1>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName w2.mydomain.com
DocumentRoot /var/www/w2
<Directory /var/www/w2>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>

Apache httpd.conf settings for virtual hosting from different directories

I have 3 websites running on a cloud server, with the default Apache httpd.conf setting . I have uncommented the NameVirtualHost and configured the 3 websites from VirtualHost, after set up the DocumentRoot and ServerName for each, all worked perfectly but only the site within the default Directory is working for mod-rewrite, which I used for SEO URLs. The other 2 sites are located just one level above the /var/www/html, and are in the subfolder of /var/www/websites/site1, site2. I've tried to use RewriteBase in the .htaccess file to make this work but no success, and I have no idea where in the httpd.conf file I can make any changes to get things right. Please help, thanks.
If I understand you correctly you wish to have 3 separate websites running on 1 Apache server and then be able to have rewrites working on all of them.
You are on the right track using VirtualHosts. You need to stick to using a separate VirtualHost for each website you intend to host.
Given a folder structure as follows
/var/www/
- /websites
-- /site1
-- /site2
-- /site3
You can then setup 3 VirtualHosts for each of your 3 sites:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain1.tld
DocumentRoot /var/www/websites/site1
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.tld
DocumentRoot /var/www/websites/site2
</VirtualHost>
<VirtualHost *:80>
ServerName www.domain2.tld
DocumentRoot /var/www/websites/site3
</VirtualHost>
Hope this helps.

Resolving virtual hosts apache 2

I'm trying to setup my apache server to access certain folders when I type addresses like test1.example.com test2.example.com etc.
So far I read and did many things but with no success yet. I'll be very thankful if you can help me.
So to start I'm using ubuntu 12.10 as my desktop and I've set up apache server there. I've added example.com in hosts resolving to 127.0.0.1. So far no problems. I've enable vhost_alias and mod_rewrite in apache and I'm using this for my virtual server
NameVirtualHost *:80
UseCanonicalName Off
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?([^\.]+).example.com$
RewriteRule ^(.*) $1 [F]
VirtualDocumentRoot /home/example/server/projects/%1/public_html
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /home/radoslav/server/projects>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
#log file for this server
CustomLog /var/log/apache2/example.com.log combined
</VirtualHost>
But when I open test.example.com it says that browser can find test.example.com, no matter that I have this directory in the path specified. Just to clear things up apache have permissions to read this directory so it's not this. When I ping example.com from console I get ping but if I ping test.example.com I get error that can not find host. As you can see obviously it's not resolving the adress no matter that I've setup everything correcly.
Any help guys?
You need to add test.example.com and any other hostnames you want to use in the host file. The host file does not supports wildcard.

Problems with Apache Virtual Hosts

I have recently just set up a RHEL based server running two domains. However, I am having difficulty hitting both domains from the browser. My config is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domainA.com
ServerAlias domainA.com *.domainA.com
DocumentRoot /home/domainA/public_html
<Directory "/home/domainA/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName domainB.com
ServerAlias domainB.com *.domainB.com
DocumentRoot /home/domainB/public_html
<Directory "/home/domainB/public_html">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
The problem is when I navigate to domainA.com I hit the correct Virtualhost (which is fine), however when I navigate to domainB.com it displays the Apache Test page.
Edit
I have a Firewall between the webserver and the web. I tested the rules governing Domain A and Domain B.
Domain A reaches target and a status 200 is returned.
Domain B reaches target and a status 403 (permission denied) is returned
What you need to do is take a look at sites-enabled and sites-available.
Here's the first entry when Googling: http://www.debian-administration.org/articles/412
Looks reasonable and should help you integrate that.
The problem is that you need separate entries for all the sites you want to run on this apache2. Simple entries in your config file don't do it. Only the first works, the rest is more or less ignored. Creating separate entries with sites-enabled and sites-available is the way to go here.

Resources