Linux上搭建Asp.net MVC3环境(CentOS + Nginx + Mono)


MVC3运行目标环境
  • Linux:CentOS6.2
  • Nginx:1.2
  • Mono:2.11.4
  • xsp:2.10.2.0

 

 安装步骤:

1、下载程序源码(大家可以进入官网下载)

    2、编译源码并安装
      •  这里将下载回来的3个源码包编译并安装,安装过程中如果提醒缺少组件,大家自己安装即可。
      • 一些需要主要使用的组件,通过yum来安装: 
        yum install gcc gcc-c++ glibc glibc-devel glib2
      • 编译安装Nginx:
        tar -zxvf nginx- 1.2. 4.tar.gz
        cd nginx- 1.2. 4/
        ./configure
        make && make install
      •  编译安装Mono:
        复制代码
        tar -jxvf mono- 2.11. 4.tar.bz2
        cd mono- 2.11. 4/
        ./configure --prefix=/opt/mono- 2.11
        make 

        make install


         

        echo export PKG_CONFIG_PATH=/opt/mono/lib/pkgconfig:$PKG_CONFIG_PATH>>~/.bash_profile
        echo export LD_LIBRARY_PATH=/opt/mono/lib:$LD_LIBRARY_PATH>>~/.bash_profile
        echo export PATH=/opt/mono/bin:$PATH>>~/.bash_profile
        source ~/.bash_profile 

         

        复制代码

      • 安装xsp: 
        tar -jxvf xsp- 2.10. 2.tar.bz2
        cd xsp- 2.10. 2/
        ./configure --prefix=/opt/mono- 2.11

        make && make install 

       4、配置Nginx

      •  添加fastcgi参数:
        vi /usr/ local/nginx/conf/fastcgi_params

        --添加2行
        fastcgi_param  PATH_INFO           "";
        fastcgi_param  SCRIPT_FILENAME     $document_root$fastcgi_script_name;
      •  添加Nginx服务器,监听9999端口:
        复制代码
        vi /usr/ local/nginx/conf/nginx.conf

        --添加一个服务器
        server{
                 listen  9999;
                server_name netserver;
                location /{
                        root  html/end;
                         index  index.html;
                        fastcgi_index /Home;
                        fastcgi_pass  127.0. 0.1: 9900;
                        include /usr/ local/nginx/conf/fastcgi_params;
                }
        }
        复制代码

       5、上传MVC3 Web程序(名称:MvcTest)

      • 使用VS2010新建一个MVC3 Web程序,将以下引用dll复制本地
        复制代码
        System.Data.dll
        System.Web.ApplicationServices.dll
        System.Web.DynamicData.dll
        System.Web.Helpers.dll
        System.Web.Mvc.dll
        System.Web.Routing.dll
        System.Web.WebPages.Deployment.dll
        System.Web.WebPages.dll
        System.Web.WebPages.Razor.dll
        复制代码
      •  手工将System.Web.Razor.dll复制到bin目录下
        dll所在目录 C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1. 0\Assemblies
      •  上传程序到Nginx的Web目录里(如不存在目录则创建)
        /usr/ local/nginx/html/end/

       6、测试MVC程序是否正常执行

      • 进入MvcTest目录
        cd /usr/ local/nginx/html/end/MvcTest
      •  运行xsp4
        复制代码
        xsp4

        Listening on address:  0.0. 0.0
        Root directory: /usr/ local/nginx/html/end/MvcTest
        Listening on port:  8080 (non-secure)
        Hit  Return to stop the server.
        复制代码
      •  使用浏览器通过8080端口测试访问,如果正常运行,恭喜你!如果出现错误,需要解决错误后才能接着往下配置。(面列了一些常见错误及解决方法)

       7、启动Nginx、fastcgi_server

      •  启动Nginx
        /usr/ local/nginx/sbin/nginx
      •  启动fastcgi_server
        fastcgi-mono-server4 /applications=/:/usr/ local/nginx/html/end/MvcTest/ / socket=tcp: 127.0. 0.1: 9900 /printlog=True
      •  fastcgi_server后台运行方法(后台长时间运行)
        nohup fastcgi-mono-server4 /applications=/:/usr/ local/nginx/html/end/MvcTest/ / socket=tcp: 127.0. 0.1: 9900 /printlog=True &

       8、所有问题解决以后就可以正常运行基本的MVC3程序了,欢呼吧~~

       

       

      常见错误及解决:
      •  xsp4启动时报错
        解决方法:移除程序bin目录下System.Web.dll

       

      • 页面显示BadGateway,后台报错 System.TypeInitializationException: An exception was thrown by the type initializer for Mono.WebServer.FastCgi.WorkerRequest
        复制代码
        --解决方法:在/opt/mono- 2.11/bin 下新建prefix.sh,并运行

        # !/bin/bash

        # Your mono directory

        PREFIX=/opt/mono-2.11
        FILES=(
                ' fastcgi-mono-server4 '
                ' xsp4 ')

        cd  $PREFIX/lib/mono/ 4.0

        for file in  " $FILES "
        do
           cp  " $file.exe " ../ 4.5
        done

        cd  $PREFIX/bin

        for file in  " $FILES "
        do
          sed -ie  ' s|mono/4.0|mono/4.5|g '  $file
        done
        复制代码
      • 页面报参数不能为空:System.ArgumentNullException Argument cannot be null. Parameter name: key;
        System.Resources.MissingManifestResourceException: Could not find any
        resources appropriate for the specified culture or the neutral
        culture.  Make sure "System.Web.Mvc.Resources.MvcResources.resources"
        was correctly embedded or linked into assembly "System.Web.Mvc" at
        compile time, or that all the satellite assemblies required are
        loadable and fully signed. 
        --解决方法:修改Web.config,在system.web节点下添加
        <globalization uiCulture= " en " culture= " en-US " />
      评论 2
      添加红包

      请填写红包祝福语或标题

      红包个数最小为10个

      红包金额最低5元

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

      抵扣说明:

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

      余额充值