How to automatically redirect HTTP traffic to HTTPS


I have successfully setup gogs on HTTPS, but whenever I accidentally try to connect on non-secure HTTP, it throws an error (as expected). Is there any way to automatically redirect those accidental calls on HTTP port to the HTTPS port?

I’m hoping to do this within the existing gogs binary, without the need to stand up another web server just to catch the HTTP requests and redirect that way.

I’m running latest build (v0.11.53) on Winx64 from binary package.


try to



@malxhn - I think you misunderstood what I’m looking for. The link you sent is similar to how I have it setup, but what I’m looking for is a simple redirect (Server 301 HTTP status code, etc) when HTTP connections are attempted, and not a connection refusal.

Here’s roughly what I’m talking about:
Connection Port -> Desired action by GOGS

HTTP_PORT -> Respond with redirect to HTTPS_PORT
HTTPS_PORT -> Serve up GOGS application as configured (SSL secured)


Hi, do it with reverse proxy (e.g. IIS), Gogs itself does not handle/care such … feature.


OK, that’s what I figured I might end up having to do. I was just hoping it might be included in GOGS to avoid setting up a secondary proxy/redirect server just for that purpose.