Mono 2.8發布:C#4.0和更好的效能,我們知道Mono 2.8對ASP.NET MVC 2的完全支援,下面我們就來測試下在Mono 2.8上部署ASP.NET MVC 2應用程式。我的環境是Opensuse 11.3,通過以下命令部署好Mono 2.8的開發環境,之所以說是開發環境是同時會更新MonoDevelop,支援Mono2.8的程式開發:
zypper addrepo http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.3 mono-stable
zypper refresh --repo mono-stable
zypper dist-upgrade --repo mono-stable
然後啟動MonoDevelop產生一個ASP.NET MVC 2應用程式TestMvc2。
我們使用Apache2 + mod_mono進行部署,設定一個虛擬機器主機:
1: <VirtualHost *:80>
2: ServerAdmin webmaster@dotnetting.com
3: ServerName www.dotnetting.com
4:
5: # DocumentRoot: The directory out of which you will serve your
6: # documents. By default, all requests are taken from this directory, but
7: # symbolic links and aliases may be used to point to other locations.
8: DocumentRoot /srv/www/vhosts/dotnetting/public_html
9:
10: # if not specified, the global error log is used
11: ErrorLog /srv/www/vhosts/dotnetting/logs/error.log
12: CustomLog /srv/www/vhosts/dotnetting/logs/access_log combined
13:
14: # don't loose time with IP address lookups
15: HostnameLookups Off
16:
17: # needed for named virtual hosts
18: UseCanonicalName Off
19:
20: # configures the footer on server-generated documents
21: ServerSignature On
22:
23:
24: # Optionally, include *.conf files from /etc/apache2/conf.d/
25: #
26: # For example, to allow execution of PHP scripts:
27: #
28: Include /etc/apache2/conf.d/mod_mono.conf
29:
30: MonoServerPath www.dotnetting.com "/usr/bin/mod-mono-server4"
31: MonoDebug www.dotnetting.com true
32: MonoSetEnv www.dotnetting.com MONO_IOMAP=all
33: MonoApplications www.dotnetting.com "/:/srv/www/vhosts/dotnetting/public_html"
34: <Location "/">
35: Allow from all
36: Order allow,deny
37: MonoSetServerAlias www.dotnetting.com
38: SetHandler mono
39: SetOutputFilter DEFLATE
40: SetEnvIfNoCase Request_URI "\.(?:gif|jpg?g|png)$" no-gzip dont-vary
41: </Location>
42: <IfModule mod_deflate.c>
43: AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
44: </IfModule>
45:
46: </VirtualHost>
這是一個通用的ASP.NET虛擬機器主機配置,唯一的一行不同就是MonoServerPath上設定的Mvc1還是mvc2,我們這裡設定為mod-mono-server4,如果你沒有修改這個地方,會收到一個錯誤是web.config 的 targetFramework不對。然後把我們產生測試程式拷貝到/srv/www/vhosts/dotnetting/public_html 。
註:Mono2.8已經移除了對.NET 1.1的支援,因此也就不能設定為mod-mono-server1
重啟Apache2
service apache2 restart
通過瀏覽器訪問www.dotnetting.com ,記得在訪問之前在host檔案中佈建網域名的解析。可以看到下面的頁面:
附:個人常用的VIM命令列表