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.11make && make install
4、配置Nginx
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
- 使用瀏覽器通過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 刪掉