Add fastcgi support and static cache headers
This commit is contained in:
parent
6a227d15a2
commit
52cc3b4dff
32
README.md
32
README.md
@ -11,19 +11,37 @@ Soon-to-be opensource replacement of Linx (media-sharing website)
|
|||||||
Get release and run
|
Get release and run
|
||||||
-------------------
|
-------------------
|
||||||
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases)
|
1. Grab the latest binary from the [releases](https://github.com/andreimarcu/linx-server/releases)
|
||||||
2. Run ```./linx-server-v...```
|
2. Run ```./linx-server...```
|
||||||
|
|
||||||
|
|
||||||
Command-line options
|
Command-line options
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
- Specify what to bind to ```-b 0.0.0.0:8080```
|
- ```-b 127.0.0.1:8080``` -- what to bind to (default is 127.0.0.1:8080)
|
||||||
- Specify the sitename ```-sitename myLinx```
|
- ```-sitename myLinx``` -- the site name displayed on top (default is linx)
|
||||||
- Specify the siteurl (for generating link) ```-siteurl "http://mylinx.example.org/"```
|
- ```-siteurl "http://mylinx.example.org/"``` -- the site url (for generating links)
|
||||||
- Specify the filespath (where files are uploaded to) ```-filespath files/"```
|
- ```-filespath files/"``` -- Path to store uploads (default is files/)
|
||||||
- Specify the metapath (where metadata for files are stored) ```-metapath meta/```
|
- ```-metapath meta/``` -- Path to store information about uploads (default is meta/)
|
||||||
- Optionally: Specify to disable request logs in stdout ```-nologs```
|
- ```-fastcgi``` -- (optionally) serve through fastcgi
|
||||||
|
- ```-nologs``` -- (optionally) disable request logs in stdout
|
||||||
|
|
||||||
|
Deployment
|
||||||
|
----------
|
||||||
|
A suggetsed deployment is running nginx in front of linx-server serving through fastcgi.
|
||||||
|
An example configuration:
|
||||||
|
```
|
||||||
|
server {
|
||||||
|
...
|
||||||
|
server_name yourlinx.example.org;
|
||||||
|
...
|
||||||
|
|
||||||
|
client_max_body_size 4096M;
|
||||||
|
location / {
|
||||||
|
fastcgi_pass 127.0.0.1:8080;
|
||||||
|
include fastcgi_params;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Development
|
Development
|
||||||
-----------
|
-----------
|
||||||
|
@ -42,6 +42,8 @@ func staticHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Etag", timeStartedStr)
|
||||||
|
w.Header().Set("Cache-Control", "max-age=86400")
|
||||||
http.ServeContent(w, r, filePath, timeStarted, file)
|
http.ServeContent(w, r, filePath, timeStarted, file)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
13
server.go
13
server.go
@ -6,8 +6,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/fcgi"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/GeertJohan/go.rice"
|
"github.com/GeertJohan/go.rice"
|
||||||
@ -24,12 +26,14 @@ var Config struct {
|
|||||||
allowHotlink bool
|
allowHotlink bool
|
||||||
siteName string
|
siteName string
|
||||||
siteURL string
|
siteURL string
|
||||||
|
fastcgi bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var Templates = make(map[string]*pongo2.Template)
|
var Templates = make(map[string]*pongo2.Template)
|
||||||
var TemplateSet *pongo2.TemplateSet
|
var TemplateSet *pongo2.TemplateSet
|
||||||
var staticBox *rice.Box
|
var staticBox *rice.Box
|
||||||
var timeStarted time.Time
|
var timeStarted time.Time
|
||||||
|
var timeStartedStr string
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
if Config.noLogs {
|
if Config.noLogs {
|
||||||
@ -70,6 +74,7 @@ func setup() {
|
|||||||
|
|
||||||
staticBox = rice.MustFindBox("static")
|
staticBox = rice.MustFindBox("static")
|
||||||
timeStarted = time.Now()
|
timeStarted = time.Now()
|
||||||
|
timeStartedStr = strconv.FormatInt(timeStarted.Unix(), 10)
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
|
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
|
||||||
@ -110,6 +115,8 @@ func main() {
|
|||||||
"name of the site")
|
"name of the site")
|
||||||
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
|
flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
|
||||||
"site base url (including trailing slash)")
|
"site base url (including trailing slash)")
|
||||||
|
flag.BoolVar(&Config.fastcgi, "fastcgi", false,
|
||||||
|
"serve through fastcgi")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
@ -119,5 +126,9 @@ func main() {
|
|||||||
log.Fatal("Could not bind: ", err)
|
log.Fatal("Could not bind: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
goji.ServeListener(listener)
|
if Config.fastcgi {
|
||||||
|
fcgi.Serve(listener, goji.DefaultMux)
|
||||||
|
} else {
|
||||||
|
goji.ServeListener(listener)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user