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


使用數據庫報錯:

System.InvalidProgramException: Invalid IL code in System.Data.Common.DbPr
oviderFactories:GetFactory (string): method body is empty.
--解決方法:將bin下的System.Data.dll 刪掉

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM