ASP.NET MVC + Mono + Nginx基础

如果是Ubuntu Desktop,则在软件中心中安装Nginx、mono-fastcgi-server4(或server2)
如果是CentOS,则用yum install安装以上工具,并安装mono相关环境
 
使用MonoDevelop可以创建、编辑、编译、发布ASP.NET MVC程序。
 
以Ubuntu 11.10为例,Nginx的默认www文件夹在/usr/share/nginx/www/,配置文件在/etc/nginx/nginx.conf。
  • 首先使用MonoDevelop创建一个MVC项目,并发布到/usr/share/nginx/www/MyTest文件夹,如果发布提示没有权限,则可以先cd至/usr/share/nginx/www,然后执行sodu chmod 777 * -R,为该文件夹赋予所有人读写的权限(生产环境不要这么做。。。);
  • 然后sodu gedit /etc/nginx/nginx.conf,在http节点中插入server节点:
server{
          listen 80;
          server_name MyTest;
          location ~ {
               root /usr/share/nginx/www/MyTest/;
               index Default.aspx default.aspx index.aspx Index.aspx index.html index.htm default.htm;
               fastcgi_index Default.aspx;
               fastcgi_pass 127.0.0.1:9000;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include /etc/nginx/fastcgi_params;
          }
     }
  • 编辑/etc/nginx/fastcgi_params,加入fastcgi_param PATH_INFO ""; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  • 执行sudo /etc/init.d/nginx restart,重启nginx;
  • 执行sudo fastcgi-mono-server4 /applications=/:/usr/share/nnx/www/MyTest /socket=tcp:127.0.0.1:9000,让mono fastcgi开始侦听9000端口上的请求;
  • 将/usr/share/nginx/www/index.html改名或者删除,这样nginx解析localhost时不会返回默认的index.html页面,此时再访问http://localhost/应该就能看到mvc程序默认的Home/Index中的界面了
posted @ 2012-10-20 19:48  火星老蒋  阅读(629)  评论(0编辑  收藏  举报