设为首页 收藏本站
查看: 433|回复: 0

[经验分享] ubuntu 12.04 nginx+ mono

[复制链接]

尚未签到

发表于 2018-5-5 14:52:33 | 显示全部楼层 |阅读模式
  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 = &quot;Hello, world!&quot;;
  •   %>
  •   <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
  •   <htmlxmlns=&quot;http://www.w3.org/1999/xhtml&quot;>
  •   <headrunat=&quot;server&quot;>
  •   <title>Untitled Page</title>
  •   </head>
  •   <body>
  •   <formid=&quot;form1&quot;runat=&quot;server&quot;>
  •   <div>
  •   <asp:Labelrunat=&quot;server&quot;id=&quot;HelloWorldLabel&quot;></asp:Label>
  •   </div>
  •   </form>
  •   </body>
  •   </html>
  

  

  

  

  本文只是尝试mono在linux下的具体实现方法,点到为止,
  由于不是生产环境,性能和稳定性没有深入测试。
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-456272-1-1.html 上篇帖子: [菜鸟级]Ubuntu Java 开发环境搭建 下篇帖子: ubuntu安装apache php mysql phpmyadmin
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表