字数:2335
本文主要介绍:
- 如何使用mono神器
- 如何nginx反向代理到mono的服务
神器mono
mono主要解决跨平台应用的,官宣为Mono is an open source implementation of Microsoft's .NET Framework based on the ECMA standards for C#and the Common Language Runtime.
在ubuntu上的安装很简单(参考这里)
Ubuntu 16.04上大体的过程即是:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt-get update
安装完后验证也是非常地简单(参考这里),写一段代码,保存为hello.cs
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
然后编译:csc hello.cs
,即产生一个hello.exe文件,运行mono hello.exe
,即打印Hello Mono World
。
测试ASP.NET也是非常简单,写以下代码,保存为hello.aspx:
<%@ Page Language="C#" %>
<html>
<head>
<title>Sample Calendar</title>
</head>
<asp:calendar showtitle="true" runat="server">
</asp:calendar>
在当前目录下运行http服务xsp4 --port 9000
,访问http://localhost:9000/hello.aspx即看到网页。
nginx反向代理
配置非常地简单:
server {
listen 80;
server_name www.domain1.xyz;
access_log /var/log/nginx/your.domain1.xyz.access.log;
root /var/www/www.domain1.xyz/;
location / {
index index.html index.htm default.aspx Default.aspx;
fastcgi_index Default.aspx;
fastcgi_pass 127.0.0.1:9000;
include /etc/nginx/fastcgi_params;
}
}
在/etc/nginx/fastcgi_params里面添加以下两行,大概用意就是说访问location的页面从哪里获得文件,也可以配到server里,但是它作为全局配置更加方便一点:
fastcgi_param PATH_INFO "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
启动mono的方法:
fastcgi-mono-server4 /applications=donet.abc.com:/:/var/www/web/.net/,mydomain.abc.com:/:/var/www/web/mydomain/ /socket=tcp:127.0.0.1:9000
可见,多个网站之间用半角逗号间隔。更多详情参考(这里)
总结
运行.NET内容非常地便利,但是ASP的页面在此无法运行,如果ASP页面里读取MDB数据库,那估计更没辙了。另一篇有介绍:在win10下配置ASP网站