您的位置:首页 > 运维架构 > Nginx

在Windows系统中用nginx与mono搭建asp.net运行环境,附详细例图与代码

2012-01-30 14:53 726 查看
一、下载nginx安装包和mono安装包



下载Nginx:到Nginx下载对应的版本

下载Mono对应平台:下载 Mono

二、安装配置

解压nginx到C:盘



打开C:\nginx\conf\nginx.conf文件,并且将以下代码覆盖

worker_processes  1;
error_log  logs/error-debug.log info;

events {
worker_connections  1024;
}

http {
include       mime.types;
default_type   text/plain;
sendfile        on;

keepalive_timeout  65;
index  index.html index.htm;

server {
listen       80;
server_name localhost;
index index.aspx default.aspx;

location / {
root   C:/nginx/html/aspnetwww;

fastcgi_pass   127.0.0.1:8282;
fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
include       fastcgi_params;
}
}
}


注意:1、“80”代表监听HTTP的80端口,2、“C:/nginx/html/aspnetwww”代表网站路径,3、“127.0.0.1:8282”代表fastcgi的地址。

下一步再安装mono,安装的时候注意设置端口为我们上一步为他预留的“8282”(在这里我安装到了D:\FastCGI-Mono-Server\);

安装好mono后我们在CMD命令行中输入:

D:\FastCGI-Mono-Server\bin\fastcgi-mono-server2 /socket=tcp:127.0.0.1:8282 /root="C:\nginx\html\aspnetwww" /applications=/:. /multiplex=True

(您也可以设置一个批处理,免得每次都要打开CMD来启动fastcgi)



命令执行后会一直处于这个状态,即表示正在运行,在这里记住不要关闭此窗口。

好了,我们再来运行C:\nginx\nginx.exe,你会看到:



即表示nginx配置正确,下一步我们写一个asp.net的页面(乘法口诀)

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<% Response.Write(DateTime.Now); %>
<hr />
<pre>
<%
for (int i=1;i<10;i++)
{
for (int j=i;j<10;j++)
{
Response.Write(string.Format("{0,-10}",i + "*" + j + "=" + i * j + "    "));
}
Response.Write("\n");
}
%>
</pre>
<hr />
fastcgi-mono-server2 /socket=tcp:127.0.0.1:8282 /root="C:\nginx\html\aspnetwww" /applications=/:. /multiplex=True
<hr />
tasklist /fi "imagename eq nginx.exe"


查下运行结果:



好了,配置成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: