Compare commits
5 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
c2988465f4 | |
|
|
ce8f7d441f | |
|
|
c480e8aa43 | |
|
|
aef0b4cb3b | |
|
|
a45aaf14c3 |
108
README.md
108
README.md
|
|
@ -1,2 +1,106 @@
|
|||
# http-to-https
|
||||
The most simple http to https service
|
||||
<br />
|
||||
<div id="readme-top" align="center">
|
||||
<a href="https://github.com/itsmrval/http-to-https">
|
||||
<img src="https://raw.githubusercontent.com/itsmrval/http-to-https/main/logo.png" alt="Logo" width="120" height="120">
|
||||
</a>
|
||||
|
||||
<h3 align="center">http-to-https</h3>
|
||||
|
||||
<p align="center">
|
||||
Simplest http to https redirector
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://github.com/itsmrval/http-to-https/issues">Report Bug</a>
|
||||
·
|
||||
<a href="https://github.com/itsmrval/http-to-https/pulls">Pull request</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Table of contents</summary>
|
||||
<ol>
|
||||
<li>
|
||||
<a href="#about-the-project">What is http-to-https ?</a>
|
||||
<ul>
|
||||
<li><a href="#built-with">Built with</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting started</a>
|
||||
<ul>
|
||||
<li><a href="#installation">Installation</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#license">License</a></li>
|
||||
</ol>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
## What is http-to-https
|
||||
|
||||
http-to-https is a simple request redirector from http to https that log request and allow custom ports.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
### Built With
|
||||
|
||||
This section list major frameworks/libraries used
|
||||
|
||||
* 
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
|
||||
## Getting Started
|
||||
|
||||
Now let's see how to set up an http-to-https instance.
|
||||
|
||||
### Installation
|
||||
|
||||
1. Create directory
|
||||
```sh
|
||||
mkdir /opt/http-to-https
|
||||
cd /opt/http-to-https
|
||||
```
|
||||
2. Download the latest release and apply permissions
|
||||
```sh
|
||||
wget -O http-to-https https://github.com/itsmrval/http-to-https/releases/download/1.1.0/http-to-https_linux_amd64
|
||||
chmod +x http-to-https
|
||||
```
|
||||
3. Create the service on systemd
|
||||
Write the file
|
||||
```sh
|
||||
nano /etc/systemd/system/http-to-https.service
|
||||
```
|
||||
Complete and put the service file below:
|
||||
```txt
|
||||
[Unit]
|
||||
Description=http-to-https service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/opt/http-to-https/http-to-https
|
||||
Environment="PORT=80"
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
6. Reload systemd and run the service !
|
||||
```sh
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now http-to-https
|
||||
```
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the MIT License. See `LICENSE` for more information.
|
||||
|
||||
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
||||
|
|
|
|||
13
src/main.go
13
src/main.go
|
|
@ -3,16 +3,23 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "80"
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
targetURL := "https://" + r.Host + r.RequestURI
|
||||
log.Printf("[REDIRECT] %s - %s (%s)", targetURL, r.RemoteAddr, r.UserAgent())
|
||||
http.Redirect(w, r, targetURL, http.StatusMovedPermanently)
|
||||
})
|
||||
|
||||
log.Println("Service running on :80")
|
||||
if err := http.ListenAndServe(":80", nil); err != nil {
|
||||
log.Fatalf("%v", err)
|
||||
log.Printf("[INFO] Service running on :%s", port)
|
||||
if err := http.ListenAndServe(":"+port, nil); err != nil {
|
||||
log.Fatalf("[ERROR] %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue