概述:
本文详细描述在
美国linux VPS配置
nginx使用
fastcgi反向代理
mono,使得linux可以支持asp.net环境,但是需要说明,真正如果网站都是asp.net语言开发的,还是建议使用
美国windows VPS配置IIS。
mono介绍:
Mono是一个有Novell公司(先前是Ximian)主持的项目。该项目的目标是创建一系列符合标准ECMA(Ecma-334和Ecma-335)的NET工具,包括C#编译器和共同语言(CL 即Common Language)执行平台(Platform)。与微软的.NAT不同,Mono项目不仅运行于Windows系统内,还可以运行于Linux、FreeBSD、Unix、Mac OS X和Solaris操作系统内,不过,部分windows上的asp.net程序移植到Linux+Mono平台时需要做一些移植、修改。
Mono的安装
在CentOS 5 linux(注:目前只兼容32位系统)上,安装下面步骤安装
mono。
yum groupinstall "Development Tools"
yum install httpd build-essential gcc bzip bison pkgconfig glib-devel glib2-devel httpd-devel libpng-devel libX11-devel freetype fontconfig pango-devel ruby ruby-rdoc gtkhtml38-devel wget
cd /usr/src/
wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.6.1.tar.bz2
tar jxvf mono-2.6.1.tar.bz2
cd mono-2.6.1/
./configure --prefix=/usr
make
make install
cd ../
从SVN版本库安装fastcgi-mono-server,按下面代码操作
export PKG_CONFIG_PATH=/usr/lib/pkgconfig/:/usr/lib/
yum install subversion
cd /usr/src/
svn co http://mono-soc-2007.googlecode.com/svn/trunk/brian/FastCgi/ fastcgi-mono-server
cd fastcgi-mono-server/
./autogen.sh
make
make install
cd ../
以FastCGI方式启动fastcgi-mono-server2,监听本机的9001端口,网页根目录为/usr/share/nginx/html:
nohup /bin/sh /usr/local/bin/fastcgi-mono-server2 /socket=tcp:9001 /root=/usr/share/nginx/html 2>&1 > /dev/null &
Nginx与ASP.NET(FastCGI+Mono)的配置
nginx.conf配置文件如下:
user nobody;
worker_processes 1;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx/nginx.pid;
events {
worker_connections 51200;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml;
gzip_vary on;
server_name_in_redirect off;
server_names_hash_bucket_size 128;
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
include /etc/nginx/conf.d/*.conf;
}
新建一个虚拟主机配置文件
vi /etc/nginx/conf.d/apsnettest.conf
内容如下:
server
{
listen 80;
server_name apsnettest.15099.net;
index index.html index.htm index.aspx default.aspx;
root /usr/share/nginx/html;
location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)?$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache cache_one;
fastcgi_cache_valid 200 10m;
fastcgi_cache_valid 301 302 1h;
fastcgi_cache_valid any 1m;
fastcgi_cache_key 127.0.0.1:9000$request_uri;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
}
在上面虚拟主机配置文件中,静态HTML网页、图片、JS、CSS、Flash等使用Nginx来处理,以便得到更快的速度,文件扩展名为:.aspx .asmx .ashx .asax .ascx .soap .rem .axd .cs .config .dll的请求,由Nginx交给fastcgi-mono-server2进程处理。
启动Nginx:
/usr/sbin/nginx -c /etc/nginx/nginx.conf
启动Nginx,在
/usr/share/nginx/html目录下下载info.apsx的ASP.NET探针文件,以检查ASP.NET程序能否正常运行:
cd /usr/share/nginx/html
wget http://aspnetsysinfo.googlecode.com/files/aspnetsysinfo-revision_23.zip
unzip aspnetsysinfo-revision_23.zip
通过游览器访问http://apsnettest.15099.net/info.aspx,如果一切正常,则显示的内容如下图(只截了部分内容):