Skip to content

Instantly share code, notes, and snippets.

@mklooss
Created September 11, 2013 11:47
Show Gist options
  • Select an option

  • Save mklooss/6522487 to your computer and use it in GitHub Desktop.

Select an option

Save mklooss/6522487 to your computer and use it in GitHub Desktop.
nginx+lighttpd redmine config
-- little helper function
function file_exists(path, ftype)
local attr = lighty.stat(path)
return (attr and attr[ftype])
end
function check_path(path)
local rv = path
if (not file_exists(path, "is_file")) then
rv = nil
local html_file = path .. ".html"
if (file_exists(html_file, "is_file")) then
rv = html_file
else
-- handle directory indeces
-- we first check if we have a dir and than look for an index.html
local index_file = path .. "/index.html"
if (file_exists(path,"is_dir") and file_exists(index_file, "is_file")) then
rv = index_file
end
end
end
if rv then
lighty.env["physical.path"] = rv
end
return rv
end
-- the magic ;)
if (not check_path(lighty.env["physical.path"])) then
-- file still missing. pass it to the fastcgi backend
lighty.env["physical.rel-path"] = "/dispatch.fcgi"
lighty.env["uri.path"] = lighty.env["physical.rel-path"]
lighty.env["request.orig-uri"] = lighty.env["request.uri"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
-- fallthrough will put it back into the lighty request loop
-- that means we get the 304 handling for free. ;)
-- debugging code
-- print ("final file is " .. lighty.env["physical.path"])
$SERVER["socket"] == ":8081" {
server.document-root = "/var/www/redmine/redmine-2.3/public"
magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )
server.indexfiles = ( "dispatch.fcgi" )
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( "dispatch.fcgi" =>
((
"socket" => "/var/run/redmine-application.sock"
))
)
}
$SERVER["socket"] == ":8083" {
server.document-root = "/var/www/redmine/redmine-2.3/public"
magnet.attract-physical-path-to = ( "/etc/lighttpd/cleanurl.lua" )
server.indexfiles = ( "dispatch.fcgi" )
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( "dispatch.fcgi" =>
((
"socket" => "/var/run/redmine-application2.sock"
))
)
}
# lb spawn fcgi allows only 1 session
upstream redmine {
server 127.0.0.1:8081;
server 127.0.0.1:8083;
}
server {
listen 144.76.128.118:443 spdy ssl;
server_name redmine.local;
access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log error;
ssl on;
ssl_certificate /opt/cert/domain/server.pem;
ssl_certificate_key /opt/cert/domain/server.pem;
location / {
proxy_pass http://redmine/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /themes/ {
alias /var/www/redmine/redmine-2.3/public/themes/;
try_files $uri =404;
}
location /stylesheets/ {
alias /var/www/redmine/redmine-2.3/public/stylesheets/;
try_files $uri =404;
}
location /javascripts/ {
alias /var/www/redmine/redmine-2.3/public/javascripts/;
try_files $uri =404;
}
location /images/ {
alias /var/www/redmine/redmine-2.3/public/images/;
try_files $uri =404;
}
location /plugin_assets/ {
alias /var/www/redmine/redmine-2.3/public/plugin_assets/;
try_files $uri =404;
}
}
#!/bin/sh
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/var/lib/gems/1.8/bin/"
exec 2>&1
export RAILS_ENV="production"
export RAILS_RELATIVE_URL_ROOT=""
export RAILS_ROOT="/var/www/redmine/redmine-2.3/"
export SOCKET_FILE="/var/run/redmine-application.sock"
export PID_FILE="/var/run/redmine-application.pid"
export DEAMON_USER="redmine"
export SOCKET_USER="www-data"
# www-data is the user lighty runs as
exec /usr/bin/spawn-fcgi -P $PID_FILE -s $SOCKET_FILE -U $SOCKET_USER -u $DEAMON_USER -- $RAILS_ROOT/public/dispatch.fcgi &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment