Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

CentOS Linux 搭建 Mono + Apache + mod_mono .NET 運行環境

編輯:Linux 教學

Mono 是跨平台開源 .NET 框架,配合 Apache 和 mod_mono 可在 Linux 上運行 ASP.NET 應用。本文記錄從源碼編譯安裝全過程,含依賴解決、模塊配置及測試驗證。

環境準備與依賴安裝

yum install bison make gcc gcc-c++ libstdc++-devel gettext pkgconfig glib2-devel

核心組件編譯安裝

  1. libgdiplus(System.Drawing 依賴)
    解決缺少 libtiff、libjpeg、giflib、libpng 等庫:
    yum install libtiff-devel libjpeg-devel giflib-devel libpng-devel libX11-devel freetype-devel fontconfig-devel libexif-devel
    編譯:./configure --prefix=/usr/local && make && make install
  2. Mono 2.10.2
    ./configure --prefix=/usr/local && make && make install
    驗證:mono -V
  3. Apache 2.2.21
    ./configure --prefix=/usr/local/apache --enable-mods-shared=most && make && make install
  4. mod_mono 2.10
    ./configure && make && make install
  5. xsp 2.10.2(mod-mono-server)
    若報錯 Package requirements (mono >= 2.10.0) were not met,設置環境變量:
    export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Apache 整合配置

  1. 編輯 /usr/local/apache/conf/httpd.conf,在 MPM 配置前添加:
    Include /usr/local/apache/conf/mod_mono.conf
  2. 取消註釋 ServerName www.example.com:80 避免啟動警告
  3. 創建測試頁面 /usr/local/apache/htdocs/test.aspx(C# 代碼)
  4. 重啟 Apache:/usr/local/apache/bin/apachectl restart

架構原理

Apache(通訊框架)←→ mod_mono(接口橋)←→ xsp(ASP.NET 處理引擎,監聽本地端口)。請求流向:客戶端 → Apache → mod_mono → xsp → 返回處理結果。

開機自啟動

echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.local
Copyright © Windows教程網 All Rights Reserved