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

來源:互聯網
上載者:User

 

MVC3運行目標環境
  • Linux:CentOS6.2
  • Nginx:1.2
  • Mono:2.11.4
  • xsp:2.10.2.0

 

 安裝步驟:

1、下載程式源碼(大家可以進入官網下載)

    • Nginx 源碼包: http://nginx.org/download/nginx-1.2.4.tar.gz
    • Mono 源碼包:http://download.mono-project.com/sources/mono/
    • xsp 源碼包:http://download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2

    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
      •  運行xsp4xsp4

        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_serverfastcgi-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" />

      使用資料庫報錯:

      System.InvalidProgramException: Invalid IL code in System.Data.Common.DbPr
      oviderFactories:GetFactory (string): method body is empty.

      --解決方案:將bin下的System.Data.dll 刪掉

       

       

       

      相關文章

      聯繫我們

      該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

      如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

      A Free Trial That Lets You Build Big!

      Start building with 50+ products and up to 12 months usage for Elastic Compute Service

      • Sales Support

        1 on 1 presale consultation

      • After-Sales Support

        24/7 Technical Support 6 Free Tickets per Quarter Faster Response

      • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.