Alexander Sayapin Teacher's site

Installing lighttpd+mono on Debian/Ubuntu (even Raspberry Pi!)

Posted on Tue 14 March 2017

In Общие вопросы.

tags: setup lighttpd mono asp.net


It is important to use most lightweigt apps on a server, either dedicated or VPS, so i decided to use lighttpd as web-server with fast-cgi support and... i have legacy apps written using asp.net/asp.net mvc :) Nowadays it is not a problem to run asp.net on Linux, cause we have mono :)

I had to connect both lighttpd and mono together.

Let's get started.

First of all, let us install lighttpd and mono fastcgi server:

sudo apt-get install lighttpd mono-fastcgi-server

Now you can check if the lighttpd works (just point your favorite browser to the address of you server), and in the server command line you can check the version of the mono:

mono -V

If everything is ok, it is time to tune the configuration of the lighttpd.

First of all, enable the fastcgi: uncomment (or add if it is not present) the line

"mod_fastcgi",

in the server.modules section of the /etc/lighttpd/lighttpd.conf file.

Your server.modules section now should look like this:

server.modules = (
    "mod_access",
    "mod_fastcgi",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
    "mod_rewrite",
)

At the end of the file add the following lines:

$HTTP["url"] =~ "^/"{ fastcgi.server = (
 "" => ((
#To be added
"socket" => "/tmp/fastcgi-mono-server4",
"bin-path" => "/usr/bin/fastcgi-mono-server4",
"bin-environment" => (
"PATH" => "/bin:/usr/bin",
"LD_LIBRARY_PATH" => "/usr/lib:",
"MONO_SHARED_DIR" => "/tmp/",
"MONO_FCGI_LOGLEVELS" => "Error",
"MONO_FCGI_LOGFILE" => "/tmp/fastcgi.log",
"MONO_FCGI_ROOT" => server.document-root,
"MONO_FCGI_APPLICATIONS" => "/:/var/www/" ),
"max-procs" =>4,
"check-local" => "disable"
 )) )
}

# Add index.aspx and default.aspx to the list of files to check when a directory is requested.
index-file.names += ( "index.aspx", "default.aspx", "index.cshtml", "default.cshtml" )
fastcgi.map-extensions = (
 ".asmx" => ".aspx",
 ".ashx" => ".aspx",
 ".asax" => ".aspx",
 ".ascx" => ".aspx",
 ".soap" => ".aspx",
 ".rem" => ".aspx",
 ".axd" => ".aspx",
 ".cs" => ".aspx",
 ".config" => ".aspx",
 ".dll" => ".aspx" )

Now your file looks like this:

server.modules = (
    "mod_access",
    "mod_fastcgi",
    "mod_alias",
    "mod_compress",
"mod_redirect",
    "mod_rewrite",
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

$HTTP["url"] =~ "^/"{ fastcgi.server = (
 "" => ((
#To be added
"socket" => "/tmp/fastcgi-mono-server4",
"bin-path" => "/usr/bin/fastcgi-mono-server4",
"bin-environment" => (
"PATH" => "/bin:/usr/bin",
"LD_LIBRARY_PATH" => "/usr/lib:",
"MONO_SHARED_DIR" => "/tmp/",
"MONO_FCGI_LOGLEVELS" => "Error",
"MONO_FCGI_LOGFILE" => "/tmp/fastcgi.log",
"MONO_FCGI_ROOT" => server.document-root,
"MONO_FCGI_APPLICATIONS" => "/:/var/www/" ),
"max-procs" =>4,
"check-local" => "disable"
 )) )
}

# Add index.aspx and default.aspx to the list of files to check when a directory is requested.
index-file.names += ( "index.aspx", "default.aspx", "index.cshtml", "default.cshtml" )
fastcgi.map-extensions = (
 ".asmx" => ".aspx",
 ".ashx" => ".aspx",
 ".asax" => ".aspx",
 ".ascx" => ".aspx",
 ".soap" => ".aspx",
 ".rem" => ".aspx",
 ".axd" => ".aspx",
 ".cs" => ".aspx",
 ".config" => ".aspx",
 ".dll" => ".aspx" )

It is enough if you are going to put your asp.net application in the root of your site. If you are, you are free to put your index.aspx file to the /var/www folder and restart your lighttpd server with the command

sudo /etc/init.d/lighttpd restart

or check the configuration file before with the command

lighttpd -t -f /etc/lighttpd/lighttpd.conf

(if you see Syntax OK everything is ok) and then restart the lighttpd server.

But if you are going to use lighttpd both as simple and lightweight static html files server and as asp.net serever at the same time (as I do), there should be some changes.

Let's imagine you are going to access your asp.net app via /test virtual path and your files are stored in the /home/site/htdocs folder. So you have to make a few changes.

Now your file should look like this:

server.modules = (
    "mod_access",
    "mod_fastcgi",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
    "mod_rewrite",
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

$HTTP["url"] =~ "^/test/"{ fastcgi.server = (
 "" => ((
#To be added
"socket" => "/tmp/fastcgi-mono-server4",
"bin-path" => "/usr/bin/fastcgi-mono-server4",
"bin-environment" => (
"PATH" => "/bin:/usr/bin",
"LD_LIBRARY_PATH" => "/usr/lib:",
"MONO_SHARED_DIR" => "/tmp/",
"MONO_FCGI_LOGLEVELS" => "Error",
"MONO_FCGI_LOGFILE" => "/tmp/fastcgi.log",
"MONO_FCGI_ROOT" => server.document-root,
"MONO_FCGI_APPLICATIONS" => "/test:/home/pi/htdocs" ),
"max-procs" =>1,
"check-local" => "disable"
 )) )
}

# Add index.aspx and default.aspx to the list of files to check when a directory is requested.
index-file.names += ( "index.aspx", "default.aspx", "index.cshtml", "default.cshtml" )
fastcgi.map-extensions = (
 ".asmx" => ".aspx",
 ".ashx" => ".aspx",
 ".asax" => ".aspx",
 ".ascx" => ".aspx",
 ".soap" => ".aspx",
 ".rem" => ".aspx",
 ".axd" => ".aspx",
 ".cs" => ".aspx",
 ".config" => ".aspx",
 ".dll" => ".aspx" )

Note the lines

$HTTP["url"] =~ "^/test/"{ fastcgi.server = (

and

"MONO_FCGI_APPLICATIONS" => "/test:/home/pi/htdocs" ),

They define the name of the virtual directory on the server (/test/) and the name of the folder on the server disk to put the asp.net files (/home/pi/htdocs).

The only flaw i see is that you cannot access your application by the virtual directory name (/test), but only by file name (/test/index.aspx). It would be highly appreciable if anyone could give me some advice on that :)


tags

алфавит (1) архитектура ЭВМ (4) asp.net (1) бгд (22) бисв (23) бкб (22) бме (22) бпэ (23) бпэз (4) бпэзу (1) бпм (20) бпм объявления (7) certbot (1) cheatsheet (1) checkinstall (1) csv (1) дискретная математика (25) экзамен (1) embedded rust (2) english (1) формальные грамматики (1) gdb (2) язык (1) исследование операций (1) jupyter (1) критерии (2) курсовая работа (2) lighttpd (2) low-latency (1) machine learning (3) make (1) make install (1) markdown (1) машинное обучение (1) математическая лингвистика (1) математическая логика (1) математическая статистика (2) Математические основы кмпьютерной графики (1) Математические основы компьютерного моделирования (1) Математические основы компьютерной графики (1) методы оптимизации (20) методы оптмимизации (1) методы принятия решений (1) миа (7) мии (8) мик (7) мим (8) миo (5) мип (9) мит (44) миу (14) миз (13) ml (1) mono (1) мпм (9) natural language processing (1) nlp (1) nucleo (2) объявления (31) оформление (2) openocd (2) openpgp (1) pandas (1) pgp (1) подтверждение вывода (1) programming (3) python (3) robot (1) robotics (2) setup (6) шпаргалка (1) системы компьютерной математики (1) smartcard (1) ssh (1) ssl (1) STM32 (2) streaming (1) строка (1) тб (21) teaching (1) teaching statement (1) Теоретические основы цифровой обработки изображений (2) тест (1) учебник (1) up board (1) video (1) вкр (2) xls (1)