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 :)