Apache2 as proxy to spring boot application ommiting slashes on login/logout - apache

I am developing a spring boot application which is being deployed on apache2 as a proxy with https. Locally everything works correctly but when I deploy the application to the server whenever I want to access the site that requires authentication I should be redirected to the login page, instead, apache2 just appends "login" to the domain name and displays error as there is no such mapping. The same situation occurs with logout. After invoking /logout there is a redirection to login?logout or login?error, both of this form works correctly as I can access them If I fix link by myself but apache2 just appends "login?logout" to domain name instead of adding slash before. Here is my virtual hosts configuration:
<VirtualHost *:80>
ServerName www.example.com
Redirect / https://example.com
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost on
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Related

Apache and Spring https redirect to wrong URL

I have a SpringBoot application running on http://localhost:8080/ and Apache. Apache redirects all requests from *:80 to *:443 and 443 to http://localhost:8080.
When I try to access http://domain_name.com/login it redirects me to https://domain_name.comlogin/
Also if i try to access pages without authentication it should redirects me to login page, but it redirects me to https://domain_name.comlogin/ instead of https://domain_name.com/login and the same with /logout
What's the problem with redirecting. Is it with Apache or Spring?
<VirtualHost *:80>
ServerName domain_name.com
ServerAdmin admin#domain_name.com
Redirect permanent / https://domain_name.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLProxyEngine On
ProxyPreserveHost On
ServerName domain_name.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/apache2/certificate/domain_name.crt
SSLCertificateKeyFile /etc/apache2/certificate/private.key
SSLCertificateChainFile /etc/apache2/certificate/chain.crt
</VirtualHost>

running website with no http show different content

Im running 3 sites in one server the same IP in Ubuntu/Apache using vhost.
I bought an SSL certificate and installed it in one of my sites successfully. The problem is when I run the site with no https it shows content from my other site.
Ex.
www.aaaaa.com
www.bbbbb.com (SSL)
www.ccccc.com
when I run https://bbbbb.com there is no problem but
when I run http://bbbbb.com it shows the content of www.aaaaa.com
I know the ssl is working correctly coz I have tested it sslchecker.
This is the first time I installed SSL, I hope someone knows something about this problem.
ok just got the Answer from this link
https://www.namecheap.com/support/knowledgebase/article.aspx/9821/38/redirect-to-https-on-apache
You just need to Redirect HTTPS on Apache. Solution is I added vhost port 80 on my conf file in apache to redirect it to https when accessing the site with no https.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#example.com
ServerName example.com.ca
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/example.com/example.ca.crt
SSLCertificateKeyFile /etc/ssl/example.com/example.key
SSLCertificateChainFile /etc/ssl/example.com/example.ca.ca-bundle
</VirtualHost>

How do I enable a site as a subdirectory of another site in Apache?

I'm trying to enable a service on my home server that has a different document root than my main site. I can't figure out how to edit the site .conf files so that I can run both the main site and the new service.
My use case: I've got a home server running Ubuntu 16.04.1 and Apache 2. I can browse to my site at ceres.local. I also installed OpenProject 6.1. After the install completes, I can browse to that service at ceres.local/openproject, but now browsing to ceres.local returns a 403 Forbidden.
I checked my sites-enabled, and I see that the 000-default.conf is no longer listed, just openproject.conf. So, I ran a2ensite 000-default.conf and service apache2 reload. Now, I can browse to ceres.local, but ceres.local/openproject returns a 404 Not Found.
How do I get both 'ceres.local' and 'ceres.local/openproject' to serve properly with the two .conf files below? Note the different document roots.
My 000-default.conf reads as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName ceres.local
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my openproject.conf reads as follows:
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName ceres.local
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
ProxyPass /openproject/ http://127.0.0.1:6000/openproject/ retry=0
ProxyPassReverse /openproject/ http://127.0.0.1:6000/openproject/
</VirtualHost>
I know is a very old post.
But I spend 3 days to solve this and is a first post when we google
so, when you install openproject he create a file called openproject.conf and disable the 000-default.conf
inside this file are a configuration like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other
#Proxypass directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
</VirtualHost>
but when you try acess the mydomain.com you receive the message 403 - forbitten
you just need modify the file like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html # <----- LOCATION WHERE YOU SITE ARE
#DocumentRoot /opt/openproject/public #<--- You Need comment this line
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other proxypass
directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
So, if can see the proxypass below, apache will redirect to then when you put mydomain.com/help (you be redirect to openproject), mydomain.com (you main site )
I Hope with this help someone
Be Happy :)

Apache2 proxy reverse broken Tomcat8 links

In my DigitalOcean vps, I have Apache2 (LAMP), phpmyadmin and Tomcat 8. Everything is running well.
Now I'm trying to implement the reverse proxy so I can access the tomcat8 not by https://mydominiam.com:8080 but by https://mydominiam.com/tomcat. After reading some tutorials, I can get this code in my /etc/apache2/sites-available/mydomain.com-ssl.conf:
<VirtualHost *:443>
ServerAdmin mydomain#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/user/ssl/mydomain.com.crt
SSLCertificateKeyFile /home/user/ssl/mydomain.com.key
SSLCertificateChainFile /home/user/ssl/intermediate.crt
# AJP configuration
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /tomcat ajp://mydomain.com:8009/
ProxyPassReverse /tomcat ajp://mydomain.com:8009/
ProxyPassReverseCookiePath / /
</VirtualHost>
The way the code above is when access https: //mydomain/tomcat, the tomcat home appears, but with broken links.
But if I change the code:
ProxyPass /tomcat ajp://mydomain.com:8009/
ProxyPassReverse /tomcat ajp://mydomain.com:8009/
for
ProxyPass / ajp://mydomain.com:8009/
ProxyPassReverse / ajp://mydomain.com:8009/
The tomcat home reloads usually no broken links, but only through the url https: //mydomain.com
I tried to follow this tutorial, but it still fails. Someone can tell me what I'm doing wrong?
Using ProxyPass with a Tomcat application where you are trying to rewrite the context path (in your configuration above, changing /tomcat to /), there are many many ways your application can break.
It is best to use a configuration like this:
ProxyPass /tomcat ajp://mydomain.com:8009/tomcat
ProxyPassReverse /tomcat ajp://mydomain.com:8009/tomcat
Now, deploy your application as /tomcat instead of the ROOT context. You can easily do that by re-naming the WAR file from ROOT.war to tomcat.war (or re-name the exploded WAR directory from ROOT to tomcat).
If you do the above, you don't have to play any games with rewriting links within pages, etc.

Redirect http to https by configuring .conf file of apache

I have configure apache to tomcat configuration by code like
<VirtualHost *:80>
ServerName captiveportal
ProxyPass / http://ip:port/path
ProxyPassReverse / http://ip:port/path
</VirtualHost>
Now i want to reirect this request to https
How can i achieve this ?
After looking your answer i have changes my configuration like
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/crt1.crt"
SSLCertificateKeyFile "/etc/httpd/conf/key1.key"
ProxyPass / http://ip:port/path
</VirtualHost>
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://ip:port/path
</VirtualHost>
but when i type captiveportal on my browser it redirects me on url https://ip:port/path and it displays problem loading page
One more thing i don't want to display https://ip:port/path on browser.
Note :- https://ip:port/path where port is my tomcat port and ip is machine ip where tomcat run.
You could do something like this:
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://my.host.name/
</VirtualHost>
...and then put your ProxyPass directives in side your SSL VirtualHost block instead.