I had a particular need with Shoutcast (since the application is 1) able to do HTTP and HTTPS on the same port, and 2) since I wanted to reverse proxy those requests for security filtering with ModSecurity) to have HTTP requests that hit the HTTPS port to upgrade those requests to HTTPS on the same port instead of just erroring out (bad protocol error). Some of this had to do with browser and other client-end mechanisms forcing an HTTPS upgrade of late, but finding it wasn’t working correctly all the time. I struggled to find a good solution but came to an answer finally on stackoverflow. I’m documenting it here for future reference and for those that may need that kind of functionality since it’s a very specific request. I normally just do a 301 redirect for situations like this, but it doesn’t seem to work when streaming media for whatever reason using particular media clients. This has done the trick.
Tag: Redirect
For some reason I found this rule to be difficult but finally got it to work thanks to the internets. This is the only rule that worked within the NGINX configuration to get only the root URL to redirect to (in my case) a non-SSL location. Here’s the section:
server {
(..)
location / {
rewrite ^(/)$ http://www.domain.com/ permanent;
}
}
http://stackoverflow.com/questions/9336261/nginx-rewrite-only-when-root-domain