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 @   火星老蒋  阅读(635)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示