I’m currently facing an issue while trying to host a Go website on my Synology NAS (DSM 7.2.1-69057 Update 5). Despite extensive troubleshooting, I’m stuck with a 403 error when trying to access the site via HTTPS.
Configuration Details
- Port Configuration:
I’ve dedicated port 8888 exclusively for my domain, example.com (note: example.com is indeed used here for assistance; the site uses a different domain). - Go Application:
Below is the code for my main.go file:
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"path/filepath"
"github.com/russross/blackfriday/v2"
)
type MarkdownTemplateData struct {
Title string
Body template.HTML
}
func renderMarkdown(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
path = "/index.md"
}
mdPath := "." + path
mdFile, err := os.ReadFile(mdPath)
if err != nil {
http.NotFound(w, r)
return
}
mdContent := blackfriday.Run(mdFile)
tmplData := MarkdownTemplateData{
Title: filepath.Base(mdPath),
Body: template.HTML(mdContent),
}
tmpl, err := template.ParseFiles("template.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
tmpl.Execute(w, tmplData)
}
func main() {
http.HandleFunc("/", renderMarkdown)
fmt.Println("Serving on https://example.com:443")
log.Fatal(http.ListenAndServeTLS(":8888", "/usr/syno/etc/certificate/_archive/1Dih2C/fullchain.pem", "/usr/syno/etc/certificate/_archive/1Dih2C/privkey.pem", nil))
}
- Nginx Configuration:
My Nginx configuration for example.com is located in /etc/nginx/conf.d/example.conf:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /usr/syno/etc/certificate/_archive/1Dih2C/fullchain.pem;
ssl_certificate_key /usr/syno/etc/certificate/_archive/1Dih2C/privkey.pem;
location / {
proxy_pass https://127.0.0.1:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- HTML Test:
I’ve tested the setup with a simple test.html page (without Go), which works perfectly.
Troubleshooting Steps and Observations
• The Go server appears to be running correctly. The output of sudo lsof -i :8888
shows that port 8888 is listening:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
example 9663 root 3u IPv6 3355074 0t0 TCP *:8888 (LISTEN)
• The following command executed in the terminal successfully retrieves the expected HTML content: curl -k https://127.0.0.1:8888
• However, accessing the site via the browser at https://example.com results in a 403 error.
Request for Assistance
I’ve tried multiple configurations and verified that the Nginx setup, Go code, and firewall rules are correct, but the 403 error persists. Any insights or suggestions on what might be causing this issue would be greatly appreciated.
Thank you in advance for your help!