Apache2 reverse proxy to multiple docker-hosted sites (eg openhab) - docker

I have found a lot of information and help in this forum, but I could not find any solution for my proxy-problem.
I've been searching various forums and trying different options for the past few weeks, but my reverse proxy just isn't working.
I have apache2 running on Ubuntu 20.04 with several websites and also a few Docker containers in use.
Now I want to make a redirect via reverse proxy to 2 Docker websites to save me the SSL certificates.
Locally the Docker containers work
http://server1:1234 => Openhab Docker
http://server1:89 => Tasmota WebAdmin
The Apache-Conf currently looks like this
server-ssl.conf
# NameVirtualHost *:443
SSLStrictSNIVHostCheck Off
<VirtualHost *:443>
ServerName server1.com
ServerAlias *.server1.com
ServerAdmin admin#server1.com
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
</IfModule>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
RewriteEngine On
SSLCertificateFile /etc/ssl/private/server1.crt
SSLCertificateKeyFile /etc/ssl/private/server1.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
<Directory /var/www/html/>
DirectoryIndex index.htm index.html index.php
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
############################
# Beginn Reverse Proxy Settings
###########################
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /openhab/ http://127.0.0.1:1234/
Header set Set-Cookie "X-OPENHAB-AUTH-HEADER=1"
ProxyPassReverse /openhab/ http://127.0.0.1:1234/
ProxyPass /tasmota/ http://127.0.0.1:89/
ProxyPassReverse /tasmota/ http://127.0.0.1:89/
####################
# Ende Reverse Proxy Settings
###################
The result of this config is
https://my.server1.com/openhab
I see the Title "Openhab" at the tab but no website, no openhab-Icons,... like at my Home-Net
Perhaps because Openhab is using Java?
https://my.server1.com/tasmota
shows "URL not found"
If I change it to
https://my.server1.com/tasmota/login
I see the login-page without formatting.
After Login the URL changes to
https://my.server1.com/devices
but should be
https://my.server1.com/tasmota/devices
If I change it manually, I see my devices but without formatting.
I have no idea what is wrong, I thought it ist adding ProxyPass and ReverseProxyPass and the whole thing runs.
Maybe someone has a tip for me?
Of course the modules proxy, proxy_http are running.
Thanks a lot and best regards

Related

Proxy Pass Subdirectory in Apache Passenger with Rails App

I have a rails app (www.myapp.com) for which I am using Apache Passenger. The virtual host is configured as follows:
<VirtualHost *:80>
DocumentRoot "/var/www/myapp/current/public"
RailsEnv production
<directory "/var/www/myapp/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</directory>
RailsBaseURI /
</VirtualHost>
I have a blog which is hosted externally on some other domain, lets say www.myapp-blog.com. I want to 301 redirect any requests to www.myapp.com/blog or www.myapp.com/blog/* to the relevant pages on www.myapp-blog.com. Everything else should flow through my Rails app.
How should I modify the above virtual host configuration to achieve this?
use apache port forwarding technique...
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.myapp-blog.com
ServerAlias myapp-blog.com
ProxyPass / http://www.myapp.com/blog/
ProxyPassReverse / http://www.myapp.com/blog
</VirtualHost>

my rails application not work on my debian server in production

When I run my browser from my rails application on my debian server, the tree of my application appears in the browser.
I install and configure passenger and apache but it does not work.
Why?
Thanks
You most likely have your web server pointed at <some_path>/app instead of <some_path>/app/public.
Example Apache VirtualHost:
<VirtualHost *:443>
ServerName www.app.com
DocumentRoot "/var/app/current/public/"
CustomLog /var/log/apache2/app_log combined
ErrorLog /var/log/apache2/app_log
<Directory /var/app/current/public>
AllowOverride all
Options -MultiViews
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/app.crt
SSLCertificateKeyFile /etc/ssl/private/app.key
SSLCertificateChainFile /etc/ssl/certs/bundle.crt
</VirtualHost>

Share Rails 3 Phusion Passenger Deployment Between HTTP and HTTPS

I have an apache virtual host for port 80 that hosts a rails 3 phusion passenger application. I would like some actions of the application to switch to https (port 443). What is the best way to share one instance of a phusion passenger rails application between two vhosts?
Right now, I have:
<VirtualHost *:80>
ServerName mycompany.com
ServerAlias www.mycompany.com
RackBaseURI /
DocumentRoot /home/ubuntu/mycompany/public
<Directory /home/ubuntu/mycompany/public >
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and
<VirtualHost _default_:443>
ServerName shop.mycompany.com
SSLEngine On
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
ProxyPreserveHost On
SSLCertificateFile /etc/ssl/...
SSLCertificateKeyFile /etc/ssl/...
SSLCertificateChainFile /etc/ssl/...
</VirtualHost>
I know this is not ideal at all. There must be a better way. I do not want all requests to go through https due to the overhead.
Mike

Running Rails on Apache2

I have a linode server and was running a single website for dev purposes using webrick, now i want to put it into production and use Apache2 which I have installed and is up and running the classic It Work's! page which is expected.
Now I want to run multiple sites on this VPS I am using the current configuration which works fine for striaght HTML but will not run the web apps unless I run them on another port (rails s -p3500 etc) as port 80 is already taken up by Apache.
<VirtualHost *:80>
ServerName datumpoint.bizmodev.com
# ServerAlias *.example.com
DocumentRoot /var/www.bizmodev.com
<Directory "/var/www.bizmodev.com">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName homehounduk.co.uk
ServerAlias *.homehounduk.co.uk
DocumentRoot /var/www.homehounduk.co.uk
<Directory "/var/www.homehounduk.co.uk">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Do i need to use passenger or something else to get this working? i have tried changing the virtual hosts to different ports and stuff but just end up getting a 403.
Any help would be appreciated.
this line:
<VirtualHost *:80>
you are telling to your apache that it will listen to anything on port 80
it you change to something like this:
<VirtualHost www.myawesomeurl.com:80>
in this case you are telling apache that everything that comes as a request from this address (www.myawesomeurl.com) on port 80 will use that options.
I think you want something like this:
# Basically your home, like: www.myhome.com
<VirtualHost *:80>
ServerName datumpoint.bizmodev.com
# ServerAlias *.example.com
DocumentRoot /var/www.bizmodev.com
<Directory "/var/www.bizmodev.com">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
# Your custom site
<VirtualHost www.something.com:80>
ServerName homehounduk.co.uk
ServerAlias *.homehounduk.co.uk
DocumentRoot /var/www.homehounduk.co.uk
<Directory "/var/www.homehounduk.co.uk">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and dont forget to point the www.something.com to the same ip as the www.myhome.com
Combine this with passenger and you will have one server running many rails apps and many php instances or html pages or anything you want.

Multiple domains, multiple vhosts, separate rails apps

I am trying to host multiple different rails apps on the same VPS using multiple domains. I am using Apache 2.2.17 on Ubuntu 10.10. For Apache, I have multiple vhost files so that I can enable and disable particular sites easily without needing to comment them out or delete them. In addition, I am also using mod_rewrite so that the multiple domains that go to the same rails app appear to go to the same URL so I don't take a hit with search engines as far as duplicate content.
I believe that my DNS is setup properly. For each of the domains, I have a www subdomain as well as some site-specific sub-domains, such as blogs, etc. The issue I am seeing is that Apache appears to matching the www subdomain immediately and not examining the additional URL behind it. Changing ServerAlias does nothing. For example, using my setup, if I enter davidheartsrachel.com, I properly reach my wedding website. However, if I use www.davidheartsrachel.com, I reach my other website, my software development business. The URL is not re-written; it stays as davidheartsrachel.com instead of afewguyscoding.com.
The only way I have been able to properly get it to work is to use mod_rewrite in the primary vhost file to redirect to the wedding website vhost file (you can see that I have that in the primary vhost file, but it is commented out for purposes of this question). This doesn't seem proper to me? Should I get another IP and do IP vhosts instead of name-based vhosts?
When I execute apachectl -S, I get the following:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:1)
port 80 namevhost blog.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:69)
port 80 namevhost lbbs.afewguyscoding.com (/etc/apache2/sites-enabled/afewguyscoding.com:84)
port 80 namevhost davidheartsrachel.com (/etc/apache2/sites-enabled/davidheartsrachel.com:1)
port 80 namevhost dhr.afewguyscoding.com (/etc/apache2/sites-enabled/davidheartsrachel_staging:1)
Syntax OK
I notice that afewguyscoding.com is the default site - however, doesn't it have to do a full string match to determine the proper site?
Primary site's vhost file
<VirtualHost *:80>
ServerAdmin david.stites#afewguyscoding.com
ServerName afewguyscoding.com
ServerAlias davidstites.com, 5280software.com, milehigh-software.com, milehighsoftware.org
ServerAlias www.5280software.com, www.milehigh-software.com, www.milehighsoftware.org, www.davidstites.com, www.afewguyscoding.com
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
DocumentRoot /var/www/afewguyscoding/current/public
DirectoryIndex index.html
# custom log file locations
# possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel alert
ErrorLog /var/www/afewguyscoding/current/log/error.log
CustomLog /var/www/afewguyscoding/current/log/access.log combined
# allows compression of text based mime.types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{REQUEST_URI} !^/ws/
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html
#RewriteCond %{HTTP_HOST} ^www.davidheartsrachel.com$
#RewriteRule ^(.*)$ http://davidheartsrachel.com$1 [L]
RewriteCond %{HTTP_HOST} ^www.davidstites.com$
RewriteRule ^(.*)$ http://www.afewguyscoding.com$1 [R=301,L]
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
# In case I ever need CGI
#ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#<Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
#</Directory>
# how we can restrict access to documents from the local subnet
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
<Location /blog>
PassengerEnabled off
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin info#afewguyscoding.com
ServerName blog.afewguyscoding.com
DocumentRoot /var/www/wpress
DirectoryIndex index.php
<Directory /var/www/afewguyscoding/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Wedding site's vhost file
<VirtualHost *:80>
ServerAdmin info#davidheartsrachel.com
ServerName davidheartsrachel.com
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com
ServerAlias www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
# this tells rails that it will run in production mode
# this is for rails < 3.x
RailsEnv production
# this is for rails >= 3.x
RackEnv production
DocumentRoot /var/www/davidheartsrachel/current/public
DirectoryIndex index.html
# Custom log file locations
# Possible values include: debug, info, notice, warn, error, crit, alert and emerg,
LogLevel alert
ErrorLog /var/www/davidheartsrachel/current/log/error.log
CustomLog /var/www/davidheartsrachel/current/log/access.log combined
# Allows compression of text based mime types
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
FileETag None
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{REQUEST_URI} !\.(css|jpg|png|gif)$
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidwedding.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.rachelanddavidstites.com$
RewriteRule ^(.*)$ http://www.davidheartsrachel.com$1 [R=301,L]
# Static cache
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteCond /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html -f
RewriteRule ^(.*)$ /var/www/davidheartsrachel/current/tmp/cache/static$1/index.html [L]
<Directory /var/www/davidheartsrachel/current/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
If you can think of any more information that might be helpful, please, ask me to post it.
Edit:
Let me try to clear this up. In the most essential form, my question is: why does going to davidheartsrachel.com takes you to www.afewguyscoding.com and davidheartsrachel.com takes you to davidheartsrachel.com based on my configuration above
On my servers I don't define a primary site in my main httpd.conf file. I do all the virtual hosting in separate application specific conf files.
The only thing I have in my main httpd.conf is the line NameVirtualHost *:80
Here's a gist of a way you could try it. I pulled all the wedding site configuration out of your main site configuration. I set it so davidstites.com, afewguyscoding.com, and www.davidstites.com all redirect to www.afewguyscoding.com. The other domains (milehigh et al) are unaffected. I'm not sure where you wanted those to go.
All the wedding related domains redirect to www.davidheartsrachel.com.
I did notice what I think might have been a mess up in your main site configuration. Toward the end where you set your directory permissions you were using the /var/www/afewguyscoding/current/public directory instead of the /var/www/wpress that is the DocumentRoot. The correction I made there is on line 74 of the first document in that gist.
The answer is that I was incorrectly separating the entries under ServerAlias with a comma thusly:
ServerAlias rachelanddavid.net, rachelanddavidstites.com, rachelanddavidwedding.com, www.davidheartsrachel.com, www.rachelanddavidstites.com, www.rachelanddavidwedding.com, www.rachelanddavid.net
It is supposed to be a space:
ServerAlias rachelanddavid.net rachelanddavidstites.com rachelanddavidwedding.com www.davidheartsrachel.com www.rachelanddavidstites.com www.rachelanddavidwedding.com www.rachelanddavid.net

Resources