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

 
 
  1. apt-get install mono-runtime mono-fastcgi-server4 mono-fastcgi-server2


与jdk类似,查看mono版本

 
 
  1. root@ubuntu:~# mono --version

  2. Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)

  3. Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com

  4.    TLS:           __thread

  5.    SIGSEGV:       altstack

  6.    Notifications: epoll

  7.    Architecture:  amd64

  8.    Disabled:      none

  9.    Misc:          softdebug  

  10.    LLVM:          supported, not enabled.

  11.    GC:            Included Boehm (with typed GC and Parallel Mark)


安装nginx

 
 
  1. apt-get install nginx


让mono以fastcgi方式在后台跑起来,监听本地9000端口

 
 
  1. root@ubuntu:~# fastcgi-mono-server2 /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9000&  

  2. [1] 4428  

  3. root@ubuntu:~# fastcgi-mono-server4 /applications=www.abc.com:/:/usr/share/nginx/www /socket=tcp:127.0.0.1:9001&  

  4. [1] 4447  

可以根据需要,写一个开机运行脚本,譬如在rc.local 加入上面两行命令让其开机启动。


示例如下

 
 
  1. #!/usr/bin/env bash

  2. ### BEGIN INIT INFO

  3. # Provides:          monoserve.sh

  4. # Required-Start:    $local_fs $syslog $remote_fs

  5. # Required-Stop:     $local_fs $syslog $remote_fs

  6. # Default-Start:     2 3 4 5

  7. # Default-Stop:      0 1 6

  8. # Short-Description: Start fastcgi mono server with hosts

  9. ### END INIT INFO

  10. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

  11. DAEMON=/usr/bin/mono

  12. NAME=monoserver

  13. DESC=monoserver

  14. MONOSERVER=$(which fastcgi-mono-server4)

  15. MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}')

  16. WEBAPPS="www.abc.com:/:/var/www/"

  17. case "$1" in

  18.        start)

  19.                if [ -z "${MONOSERVER_PID}" ]; then

  20.                        echo "starting mono server"

  21.                        ${MONOSERVER} /applications=${WEBAPPS} /socket=tcp:127.0.0.1:9000 &

  22.                        echo "mono server started"

  23.                else

  24.                        echo ${WEBAPPS}

  25.                        echo "mono server is running"

  26.                fi

  27.        ;;

  28.        stop)

  29.                if [ -n "${MONOSERVER_PID}" ]; then

  30.                        kill ${MONOSERVER_PID}

  31.                        echo "mono server stopped"

  32.                else

  33.                        echo "mono server is not running"

  34.                fi

  35.        ;;

  36. esac

  37. exit 0


查看mono进程和本地端口

 
 
  1. root@ubuntu:~# ps -elf |grep mono

  2. 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

  3. 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

  4. 0 S root      4454  1531  0  80   0 -  2346 pipe_w 19:19 pts/0    00:00:00 grep --color=auto mono

  5. root@ubuntu:~# ss -ln

  6. State      Recv-Q Send-Q                                                    Local Address:Port                                                      Peer Address:Port  

  7. LISTEN     0      128                                                           127.0.0.1:9001                                                                 *:*      

  8. LISTEN     0      128                                                                  :::22                                                                  :::*      

  9. LISTEN     0      128                                                                   *:22                                                                   *:*      

  10. LISTEN     0      128                                                           127.0.0.1:9000                                                                 *:*      

  11. root@ubuntu:~#  


配置nginx, (注意区分大小写)


 
 
  1. server {

  2.        listen   80 ;

  3.        server_name  www.abc.com ;

  4.        access_log   /var/log/nginx/www.abc.com.access.log ;

  5.        location ~*  / {

  6.                root /var/www/ ;

  7.                index index.html index.htm default.aspx Default.aspx ;

  8.                fastcgi_pass 127.0.0.1:9000;

  9.                include fastcgi_params;

  10.        }

  11. }

在文件/etc/nginx/fastcgi_params中加入两行

 
 
  1. fastcgi_param  PATH_INFO          "";

  2. fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;


开启nginx

 
 
  1. service nginx start


找一个asp 的示例helloworld.aspx

 
 
  1. <%

  2. HelloWorldLabel.Text = "Hello, world!";

  3. %>

  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  5. <htmlxmlns="http://www.w3.org/1999/xhtml">

  6. <headrunat="server">

  7. <title>Untitled Page</title>

  8. </head>

  9. <body>

  10. <formid="form1"runat="server">

  11. <div>

  12. <asp:Labelrunat="server"id="HelloWorldLabel"></asp:Label>

  13. </div>

  14. </form>

  15. </body>

  16. </html>





本文只是尝试mono在linux下的具体实现方法,点到为止,

由于不是生产环境,性能和稳定性没有深入测试。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值