Redirect http traffic to https on a non standard apache port - https

I have a website running at https://example.com:555
The 80 and 443 port for the same public ip have been forwarded to another server.
I only want to re-direct the url from http://example.com:555/1618/?id=877 to https://example.com:555/1618/?id=877
Right now I am getting the 400 error "Your browser sent a request that this server could not understand..."
I am using apache 2.4 on ubuntu 20.04
Any leads would be highly appreciated.
Thanks.
adding "ErrorDocument 400 https://example.com:555" in .htaccess
works but the id parameter is not passed
adding ErrorDocument in the localized-error-pages.conf in apache
works but the id parameter is not passed
configure Strict-Transport-Security
didnt work
trying different $1 , REQUEST_URI etc in .htaccess
did not work

Related

Spring boot static content works fine locally but not when I push to VPS server

I have a spring boot that runs fine locally and I have no problems accessing: http://localhost:8080/staticlayouts/blah.html. Whenever I upload to my VPS running Cpanel/WHM i get the following when I try to access http://www.example.com/staticlayouts/blah.html where example.com is my website. I Have no issues accessing my main page, other than static content is not loading. Any ideas what I need to change in WHM/Cpanel configuration to get the static content of spring boot to stop getting the following error:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /staticlayouts/blah.html.
Reason: DNS lookup failure for: localhost:8080staticlayouts
Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.
After hours of wasting my time trying worthless things, the problem was because of my apache httpd configuration. In my vhost.config file I had this:
ProxyPreserveHost on
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
I needed this (notice the slashes on the urls):
ProxyPreserveHost on
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
This url is a great reference: https://medium.com/#codebyamir/using-apache-as-a-reverse-proxy-for-spring-boot-embedded-tomcat-f704da73e7c8

Passenger Standalone - Force Redirect to SSL

I've started to use Elastic Beanstalk with Ruby + Passenger Standalone which seems awesome, however I want to redirect all HTTP to HTTPS, I haven't managed to find any resource at all about this. I've been looking at customizing the nginx.conf.erb but can't really find out what to do.
Note that I already have SSL working, I just need to make all requests redirecting to SSL.
Thanks,
Johan
server {
listen 80;
server_name my.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name my.domain.com;
[....]
}
It seems to late to answer this question. Just for those who need to tackle this in the future:
Try adding "port": 80 in your Passengerfile.json, and uncommenting "config.force_ssl = true" in your config/environments/production.rb.
The first change will direct your browser's request (without specifying port or protocol, i.e. something like www.example.com) to passenger. The second line tells passenger to redirect any http request to https.

Nginx will not stop rewriting

I am attempting to configure an owncloud server that rewrites all incoming requests and ships them back out at the exact same domain and request uri but change the scheme from http to https.
This is failed miserably. I tried:
redirect 301 https://$hostname/$request_uri
and
rewrite ^ https://$hostname/$request_uri
Anyway, after removing that just to make sure the basic nginx configuration would work it as it had prior to adding the ssl redirects/rewrites it will NOT stop changing the scheme to https.
Is there a cached list somewhere in nginx's configuration that keeps hold of redirect/rewrite protocols? I cleared my browser cache completely and it will not stop.
AH HA!
in config/config.php there was a line
'forcessl' => true,
Stupid line got switched on when it received a request at the 443 port.
Turned off and standard http owncloud works and neither apache/nginx are redirecting to ssl.
Phew.

Nginx https redirects - stop further rules processing

I'm trying to configure http and https redirects from an old site to a new one.
According to the rewrite directive docs:
If the replacement string begins with http:// then the client will
be redirected, and any further rewrite directives are terminated.
And I'm trying to achieve the same with https to no avail.
This is my server config:
listen 80;
listen 443 ssl;
server_name mydomain.com
rewrite ^/path/resource(.*)$ $scheme://newdomain.com/newpath/resource$1 permanent;
...
return 301 http://newdomain.com/newpath/;
Using http I get what I'm looking for: if I access mydomain.com/path/resource I'm redirected to newdomain.com/newpath/resource.
However, the same with https redirects me to http://newdomain.com/newpath/.
I have rewrite_log on and in both cases the rewrite rule is matched but the https protocol does not stop further rules processing.
I have the feeling that either I'm missing something really obvious or I'm not approaching this problem properly. I wouldn't mind doing this in any different way at all if it works.
Have any of you out there any idea on how to achieve the http redirect with https too?
I usually like to use return instead of rewrite for redirects, try matching the path with a location block
location ~ /path/resource(.*) {
return 301 $scheme://newdomain.com/newpath/resource$1;
}
I think this way you know for sure there will be no further processing, because it's only 1 line, try it and tell me how it goes.
PS: This will maintain the $scheme of the request, requests to http:// will be redirected to a http:// and https:// will be redirected to https://

IIIS 7.5 URL rewrite to Geoserver giving Connection Reset error

I have Geoserver set up on a Windows 2008 server using Jetty as the web container on port 8080. If the browse to http://[servername]:8080/geoserver/www/test/test.html I get a html page returned as expected.
Then I have set up IIS 7.5 using ARR and URL rewrite at the application pool level, to set up a reserve proxy. So that http://[servername]/geoserver.. is rewritten to http://[servername]:8080/geoserver... I am using match '.*' for the url and 'geoserver/' for the condition.
This gives a error when browsed to of 'connection reset' IIS http error log (C:\Windows\System32\LogFiles\HTTPERR) shows 'Connection_Dropped DefaultAppPool'
If I change the url rewrite to an action of redirect, the html page is displayed as expect, but obviously the url shows as redirected to port 8080.
Solved this by changing the URL rewrite to use .* for the URL match condition.

Resources