一、下載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"
查下運行結果:
好了,配置成功