[CentOS7] 运行 [asp.net] [mono+nginx] 配置

  1. Add the Mono repository to your system
    The package repository hosts the packages you need, add it with the following commands in a root shell.
    Note:the packages should work on newer CentOS/RHEL versions too but we only test the ones listed below.
    CentOS/RHEL 8(x86_64)
rpm --import "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF" 
su -c 'curl https://download.mono-project.com/repo/centos8-stable.repo | tee /etc/yum.repos.d/mono-centos8-stable.repo' 

CentOS/RHEL 7(x86_64)

rpm --import "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF" 
su -c 'curl https://download.mono-project.com/repo/centos7-stable.repo | tee /etc/yum.repos.d/mono-centos7-stable.repo' 

CentOS/RHEL 6(x86_64, i686)

rpm --import "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF" 
su -c 'curl https://download.mono-project.com/repo/centos6-stable.repo | tee /etc/yum.repos.d/mono-centos6-stable.repo' 
  1. Install Mono
yum install mono-devel

(The package mono-devel should be installed to compile code. )

The package mono-complete should be installed to install everything – this should cover most cases of “assembly not found” errors.
The package referenceassemblies-pcl should be installed for PCL compilation support – this will resolve most cases of “Framework not installed: .NETPortable” errors during software compilation.

The package xsp should be installed for running ASP.NET applications.

yum Install xsp

输入mono -V 如有mono版本信息,则安装成功

  1. Verify Installation
    After the installation completed successfully, it’s a good idea to run through the basic hello world examples on this page to verify Mono is working correctly.

/etc/nginx/conf.d 下面增加网站配置文件,比如default.conf

内容如下:

server { 
   listen 80; 
   server_name mywebsite.com; 
   access_log /var/log/nginx/dysonkb.com.access.log;
   location / { 
     root /var/www/mywebsite; 
     index index.html index.htm Default.aspx; 
     fastcgi_index Default.aspx; 
     fastcgi_pass 127.0.0.1:9000; 
     include fastcgi_params; 
   } 
 }

配置fastcgi_params增加下面两行:

fastcgi_param  PATH_INFO          ""; 
fastcgi_param  SCRIPT_FILENAME    document_rootfastcgi_script_name; 

启动 fastcgi_mono服务器

mkdir -p /var/www/PMIARC  #存放mono处理的网站 
/user/bin/fastcgi-mono-server4 /applications=/:/var/www/mywebsite /socket=tcp:127.0.0.1:9000 &

重启nginx

systemctl restart nginx

ps:
多网站配置

fastcgi-mono-server4 --appconfigdir /var/www/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &

每个网站的配置文件名字 MonoWebApi.webapp

<apps>   
<web-application> 
        <name>MonoWebApi</name> 
        <vhost>domain.com</vhost> 
        <vport>80</vport> 
        <vpath>/</vpath> 
        <path>/var/www/domain.com</path> 
</web-application> 
</apps>
评论关闭

return top