问题描述
列在 ServiceStack 网站上,表明 ServiceStack 可以在 Mono 上运行:
Listed on the ServiceStack website it shows that ServiceStack can run on Mono with either:
- XSP
- mod_mono
- FastCgi
- 控制台
这些不同的配置是什么?哪些配置更适合 Mono 上的 Web 服务?
What are these different configurations and which is preferred for Web Services on Mono?
推荐答案
Linux 更新
来自 v4.5.2 版本 ServiceStack 现在支持 .NET Core,它提供了重要的Mono 的性能和稳定性改进源自共享的跨平台代码库,并得到 Microsoft 资源充足、积极响应的团队的支持.如果您目前在 Mono 上运行 ServiceStack,我们强烈建议您升级到 .NET Core,以利用其卓越的性能、稳定性和自上而下支持的技术堆栈.
Update for Linux
From the v4.5.2 Release ServiceStack now supports .NET Core which offers significant performance and stability improvements over Mono that’s derived from a shared cross-platform code-base and supported by Microsoft's well-resourced, active and responsive team. If you’re currently running ServiceStack on Mono, we strongly recommend upgrading to .NET Core to take advantage of its superior performance, stability and its top-to-bottom supported Technology Stack.
我们推荐的在 Linux 和 Mono 上托管 ASP .NET 站点的设置是使用 nginx/HyperFastCgi.我们在 单服务器配置.
Our recommended Setup for hosting ASP .NET sites on Linux and Mono is to use nginx/HyperFastCgi. We've published a step-by-step guide going through creating an Ubuntu VM from scratch complete with deploy / install / conf / init scripts at mono-server-config.
在注意到几个稳定性和性能问题后,我们不再推荐 MonoFastCGI.这篇博文很好地分析了 Mono 中不同的 ASP.NET 托管选项.
We're no longer recommending MonoFastCGI after noticing several stability and performance issues. This blog post provides a good analysis of the performance, memory usage and stability of the different ASP.NET Hosting options in Mono.
XSP 类似于 VS.NET WebDev 服务器 - 一个简单的独立 ASP.NET WebServer 用 C# 编写.这适用于开发或小工作量.您只需从 ServiceStack ASP.NET 主机的根目录运行它,这将使其在 http://localhost:8080
可用.
XSP is similar to VS.NET WebDev server - a simple standalone ASP.NET WebServer written in C#. This is suitable for development or small work loads. You just run it from the root directory of your ServiceStack ASP.NET host which will make it available at http://localhost:8080
.
对于外部 Internet 服务,您通常希望将 ServiceStack Web 服务托管为全功能 Web 服务器的一部分.适用于 Linux 的 2 个最受欢迎的全功能 Web 服务器是:
For external internet services you generally want to host ServiceStack web services as part of a full-featured Web Server. The 2 most popular full-featured web servers for Linux are:
使用 Mono FastCGI 在 Nginx.
使用 mod_mono 在 Apache HTTP 服务器.
ServiceStack 还支持自托管,让您可以在独立的控制台应用程序(即没有 Web 服务器)中自行运行 ServiceStack Web 服务.当您不需要功能齐全的 Web 服务器的服务时,这是一个好主意(例如:您只需要在 Intranet 上内部托管 Web 服务).
ServiceStack also supports self-hosting which lets you run your ServiceStack webservices on its own in a standalone Console application (i.e. without a web server). This is a good idea when you don't need the services of a full-featured web server (e.g: you just need to host web services internally on an Intranet).
默认情况下,相同的 ServiceStack 控制台应用程序二进制文件按原样在 Windows/.NET 和 Mono/Linux 上运行.虽然如果您愿意,您可以轻松地将您的应用程序守护到 按照此处所述作为 Linux 守护程序运行.该 wiki 页面还包含有关配置自托管 Web 服务以在 Nginx 或 Apache 反向代理之后运行的说明.
By default the same ServiceStack Console app binary runs on both Windows/.NET and Mono/Linux as-is. Although if you wish, you can easily daemonize your application to run as a Linux daemon as outlined here. The wiki page also includes instructions for configuring your self-hosted web service to run behind an Nginx or Apache reverse proxy.
因为它非常适合 Heroku 的并发模型如他们的 12 因子应用程序中所详述托管将是我们希望在不久的将来提供更多支持的领域.
Since it provides a good fit for Heroku's Concurrency model as detailed in their 12 factor app self-hosting will be an area we'll be looking to provide increased support around in the near future.
servicestack.net 网站本身(包括所有现场演示)在 Ubuntu 上运行hetzner vServer 使用 Nginx + Mono FastCGI.
The servicestack.net website itself (inc. all live demos) runs on an Ubuntu hetzner vServer using Nginx + Mono FastCGI.
该命令用于启动FastCGI后台进程:
This command is used to start the FastCGI background process:
fastcgi-mono-server4 --appconfigdir /etc/rc.d/init.d/mono-fastcgi
/socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &
它托管在使用 ,eg:
Which hosts all applications defined in *.webapp files in the /etc/rc.d/init.d/mono-fastcgi
folder specified using XSP's WebApp File Format, e.g:
ServiceStack.webapp:
ServiceStack.webapp:
<apps>
<web-application>
<name>ServiceStack.Northwind</name>
<vhost>*</vhost>
<vport>80</vport>
<vpath>/ServiceStack.Northwind</vpath>
<path>/home/mythz/src/ServiceStack.Northwind</path>
</web-application>
</apps>
这会在后台运行 FastCGI Mono 进程,您可以通过将此规则添加到 nginx.conf 来让 Nginx 连接到该进程:
This runs the FastCGI Mono process in the background which you can get Nginx to connect to by adding this rule to nginx.conf:
location ~ /(ServiceStack|RedisAdminUI|RedisStackOverflow|RestFiles).* {
root /usr/share/nginx/mono/servicestack.net/;
index index.html index.htm index.aspx default.htm Default.htm;
fastcgi_index /default.htm;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /usr/share/servicestack.net$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
这会将任何以/ServiceStack
或/RedisAdminUI
等开头的路由转发给FastCGI mono server进程进行处理.以这种方式托管的一些示例应用:
Which will forward any route starting with /ServiceStack
or /RedisAdminUI
, etc to the FastCGI mono server process for processing. Some example apps hosted this way:
- http://www.servicestack.net/ServiceStack.Northwind/
- http://www.servicestack.net/ServiceStack.Hello/
- http://www.servicestack.net/RedisAdminUI/AjaxClient/李>
- http://www.servicestack.net/RedisStackOverflow/
对于那些对 servicestack.net 的完整 Nginx + FastCGI 配置文件感兴趣的人,可供下载.
For those interested the full Nginx + FastCGI configuration files for servicestack.net are available for download.
这篇关于在 Linux/Mono 上运行 ServiceStack 的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!