Configure apache to redirect url to another host - apache

Configuration: I have 2 virtual machines:
VM1: accessible from browser with https://vm1.com
VM2: accessible from browser with 10.200.200.200:8088
What I want to do:
==> If the user will enter this url: https://vm1.com/dashboard
==> The flow will be redirected to 10.200.200.200:8088
What I try to do:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
DocumentRoot /var/www
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /dashboard http://10.200.200.200:8088/
ProxyPassReverse /dashboard http://10.200.200.200:8088/
<Directory /var/www/>
Options +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Problem:
This solution works only if the incoming url is /dashboard. If the incoming url is /dashboard/login, the redirect failed.

Related

My website URL with www shows the correct content but shows the Apache2 Ubuntu Default page without www. How do I correct this?

I followed the How To Deploy a Flask Application on an Ubuntu VPS
and How To Install the Apache Web Server on Ubuntu 20.04
from Digital Ocean where my hosting is. I have two type A DNS records set up where the hostname is my URL with www and my URL without it, that direct to the value of my public IP.
I can change which address shows the correct information by changing ServerName to either my public IP, my website with www, or my website without www. How can I make it so that www.mywebsite.com and mywebsite.com both show correctly? A redirect surely can't be the right answer?
Here is the conf file: /etc/apache2/sites-available/FlaskApp.conf
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I tried adding a permanent redirect it didn't work.
<VirtualHost *:80>
ServerName www.mywebsite.com
Redirect permanent / http://mywebsite.com/
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
For anyone else with this problem I found a solution by adding a server alias:
<VirtualHost *:80>
ServerName www.mywebsite.com
ServerAlias mywebsite.com
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

cannot letsencrypt because port 80 auto redirects to 443

I have a few sites running on a server running apache2 and I have forgotten how I auto forwarded all traffic to https. Trying to run letsencrypt but it must visit the http page first. when I wget the page I receive:
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://example.org/ [following]
I do not see anything in apache2.conf
mysite.conf
<VirtualHost *:80>
ServerAdmin admin
DocumentRoot /var/www/html/mysite/
ServerName example.org
Alias /mysite "/var/www/html/mysite/"
<Directory /var/www/html/mysite/>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html/mysite
SetEnv HTTP_HOME /var/www/html/mysite
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
mysite-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin
DocumentRoot /var/www/html/mysite/
ServerName mysite.org
ServerAlias www.example.org
Alias / "/var/www/html/mysite/"
<Directory /var/www/html/mysite/>
Options +FollowSymlinks
AllowOverride All
Require all granted
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html/mysite
SetEnv HTTP_HOME /var/www/html/mysite
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/oldsite/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/oldsite/privkey.pem
</VirtualHost>
</IfModule>
<VirtualHost *:80>
ServerAdmin admin
DocumentRoot /var/www/html/mysite/
ServerName example.org
ServerAlias www.example.org
Alias / "/var/www/html/mysite/"
<Directory /var/www/html/mysite/>
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/html/mysite
SetEnv HTTP_HOME /var/www/html/mysite
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
not sure what I need to do to allow lets encrypt to complete the certs. Any help would be greatly appreciated!

Disable SSL on specific subdomain

I have a domain say example.com using SSL. Now i have created a test site for the application and hosted in test.example.com. But whenever i am trying to access test.example.com i am getting connection not private error. That sub domain is also using the SSL somehow.
I tried to add redirect rule to http version in .htaccess and vhost files, but not working. Any solution?
Here is the default-ssl.conf file:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/frontend
DirectoryIndex index.html
<Directory /var/www/html/frontend>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine On
SSLCertificateFile /etc/ssl/certfile.crt
SSLCertificateKeyFile /etc/ssl/certkey.key
SSLCertificateChainFile /etc/ssl/gd_bundle-g2-g1.crt
</VirtualHost>
</IfModule>

running jenkins behind apache2 on subdomain and different port

I am attempting to get a jenkins instance (running on http://localhost:8080/) to be visible at http://ci.domain.com:80/.
Current status:
* Browsing to ci.domain.com gives me the content of domain.com
* Browsing to ci.domain.com:8080 shows jenkins
* Browsing to domain.com:8080 shows jenkins
Ideal status:
* Browsing to ci.domain.com shows jenkins
* Browsing to ci.domain.com:8080 redirects to ci.domain.com
* Browsing to domain.com:8080 does whatever the server would do if there were nothing running on port 8080
My current apache site config (working as expected for shifting traffic to HTTPS) is as follows:
<VirtualHost *:8080>
ServerName ci.domain.com
ServerAlias ci
Redirect temp / http://ci.domain.com/
</VirtualHost>
<VirtualHost *:80>
ServerName ci.domain.com
ServerAlias ci
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com
<Directory /var/www/domain.com/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml $
</IfModule>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/domain.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/domain.com/fullchain.pem
<FilesMatch "\.(cgi|shtml|phtml_php)$">
SSLOptions +StdEnvVars
</FilesMatch>
</VirtualHost>
Any help is appreciated.

Apache Virtual Host with path

I am deploying a Rails app with Phusion passenger and Apache HTTPD, to do that I have to create a virtual host in Apache to associate the root of my app. And this process is successful, effectively my app is running, but my problem is that I have to do this run in a path of my domain, such as "mydomain.com/railsapp".
I tried this configurations and all failed.**
Configuration 1
ServerAdmin admin#mydomain.com
ServerName mydomain.com/railsapp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Configuration 2
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerPath /railsappp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Configuration 3
ServerAdmin admin#mydomain.com
ServerName mydomain.com
ServerAlias mydomain.com/railsappp
RailsEnv production
RailsBaseURI /app
DocumentRoot /var/www/rails/app/public
<Directory /var/www/rails/app/public>
AllowOverride all
Options -MultiViews
#Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Does Anyone have idea how to do that?
Use ServerName as my domain.com and make use of ProxyPass and ProxyPassReverse directive to redirect /railsapp to desired location.... Read more about reverse proxy..