ubuntu 12.04 nginx+ mono-fastcgi-server
mono是.NET在Linux下的的開源實現, 主要的運行方式分為兩種
apache + mod_mono
nginx + fastcgi (mono)
考慮到nginx性能更好,這里講述第二種實現方法
因為Ubuntu 提供了完整的mono軟件包支持,因此本文嘗試在Ubuntu 12.04下搭建
安裝mono和fastcgi-server
apt-get install mono-runtime mono-fastcgi-server4 mono-fastcgi-server2
與jdk類似,查看mono版本
root@ubuntu:~# mono --version
Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
? ?TLS: ? ? ? ? ? __thread
? ?SIGSEGV: ? ? ? altstack
? ?Notifications: epoll
? ?Architecture: ?amd64
? ?Disabled: ? ? ?none
? ?Misc: ? ? ? ? ?softdebug ?
? ?LLVM: ? ? ? ? ?supported, not enabled.
? ?GC: ? ? ? ? ? ?Included Boehm (with typed GC and Parallel Mark)
安裝nginx
apt-get install nginx
讓mono以fastcgi方式在后臺跑起來,監聽本地9000端口
root@ubuntu:~# fastcgi-mono-server2 /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9000& ?
[1] 4428 ?
root@ubuntu:~# fastcgi-mono-server4 /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9001& ?
[1] 4447 ?
可以根據需要,寫一個開機運行腳本,譬如在rc.local 加入上面兩行命令讓其開機啟動。
示例如下
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: ? ? ? ? ?monoserve.sh
# Required-Start: ? ?$local_fs $syslog $remote_fs
# Required-Stop: ? ? $local_fs $syslog $remote_fs
# Default-Start: ? ? 2 3 4 5
# Default-Stop: ? ? ?0 1 6
# Short-Description: Start fastcgi mono server with hosts
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mono
NAME=monoserver
DESC=monoserver
MONOSERVER=$(which fastcgi-mono-server4)
MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}')
WEBAPPS="www.abc.com:/:/var/www/"
case "$1" in
? ? ? ?start)
? ? ? ? ? ? ? ?if [ -z "${MONOSERVER_PID}" ]; then
? ? ? ? ? ? ? ? ? ? ? ?echo "starting mono server"
? ? ? ? ? ? ? ? ? ? ? ?${MONOSERVER} /applications=${WEBAPPS} /socket=tcp:127.0.0.1:9000 &
? ? ? ? ? ? ? ? ? ? ? ?echo "mono server started"
? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ?echo ${WEBAPPS}
? ? ? ? ? ? ? ? ? ? ? ?echo "mono server is running"
? ? ? ? ? ? ? ?fi
? ? ? ?;;
? ? ? ?stop)
? ? ? ? ? ? ? ?if [ -n "${MONOSERVER_PID}" ]; then
? ? ? ? ? ? ? ? ? ? ? ?kill ${MONOSERVER_PID}
? ? ? ? ? ? ? ? ? ? ? ?echo "mono server stopped"
? ? ? ? ? ? ? ?else
? ? ? ? ? ? ? ? ? ? ? ?echo "mono server is not running"
? ? ? ? ? ? ? ?fi
? ? ? ?;;
esac
exit 0
查看mono進程和本地端口
root@ubuntu:~# ps -elf |grep mono
0 S root ? ? ?4428 ?1531 ?0 ?80 ? 0 - 76813 futex_ 18:59 pts/0 ? ?00:00:00 /usr/bin/mono /usr/lib/mono/2.0/fastcgi-mono-server2.exe /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9000
0 S root ? ? ?4447 ?1531 ?0 ?80 ? 0 - 76993 futex_ 19:19 pts/0 ? ?00:00:00 /usr/bin/mono /usr/lib/mono/4.0/fastcgi-mono-server4.exe /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9001
0 S root ? ? ?4454 ?1531 ?0 ?80 ? 0 - ?2346 pipe_w 19:19 pts/0 ? ?00:00:00 grep --color=auto mono
root@ubuntu:~# ss -ln
State ? ? ?Recv-Q Send-Q ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Local Address:Port ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Peer Address:Port ?
LISTEN ? ? 0 ? ? ?128 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 127.0.0.1:9001 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *:* ? ? ?
LISTEN ? ? 0 ? ? ?128 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?:::22 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?:::* ? ? ?
LISTEN ? ? 0 ? ? ?128 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *:22 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *:* ? ? ?
LISTEN ? ? 0 ? ? ?128 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 127.0.0.1:9000 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *:* ? ? ?
root@ubuntu:~# ?
配置nginx, (注意區分大小寫)
server {
? ? ? ?listen ? 80 ;
? ? ? ?server_name ?www.abc.com ;
? ? ? ?access_log ? /var/log/nginx/www.abc.com.access.log ;
? ? ? ?location ~* ?/ {
? ? ? ? ? ? ? ?root /var/www/ ;
? ? ? ? ? ? ? ?index index.html index.htm default.aspx Default.aspx ;
? ? ? ? ? ? ? ?fastcgi_pass 127.0.0.1:9000;
? ? ? ? ? ? ? ?include fastcgi_params;
? ? ? ?}
}
在文件/etc/nginx/fastcgi_params中加入兩行
fastcgi_param ?PATH_INFO ? ? ? ? ?"";
fastcgi_param ?SCRIPT_FILENAME ? ?$document_root$fastcgi_script_name;
開啟nginx
service nginx start
找一個asp 的示例helloworld.aspx
<%
HelloWorldLabel.Text = "Hello, world!";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:Labelrunat="server"id="HelloWorldLabel"></asp:Label>
</div>
</form>
</body>
</html>
本文只是嘗試mono在linux下的具體實現方法,點到為止,
由于不是生產環境,性能和穩定性沒有深入測試。
轉載于:https://blog.51cto.com/purplegrape/1122883
總結
以上是生活随笔為你收集整理的ubuntu 12.04 nginx+ mono-fastcgi-server的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 正确使用PresentModalView
- 下一篇: iphone-common-codes-