原文地址—-Kestrel server for ASP.NET Core By Tom Dykstra, Chris Ross, and Stephen Halter Kestrel是一个基于libuv的跨平台ASP.NET Core web服务器,libuv是一个跨平台的异步I/O库。ASP.NET Core模板项目使用Kestrel作为默认的web服务器。 Kestrel支持以下功能: HTTPS 用于启用不透明升级的WebSockets 位于Nginx之后的高性能Unix sockets Kestrel 被.NET Core支持的所有平台和版本所支持 查看或下载示例代码 何时使用Kestrel和反向代理服务器 如果你的应用只接收来自内部网络的请求,你可以只使用Kestrel本身。 如果你将你的应用部署在公共网络上,我们建议你使用IIS,Nginx或者Apache作为反向代理服务器。一个反向代理服务器接收来自网络的HTTP请求并且在经过一些初步处理后将请求传递到Kestrel服务器。 出于安全性的理由,反向代理常常被edge deployments所采用。因为Kestrel相对较新,对抵御安全攻击至今还没有一个完整的功能补充。安全性处理包括但不限于适当的超时,大小的限制,以及并发连接限制等问题。 另一个需要反向代理的场景是,你有多个需要在单独的服务器上运行并分享同一端口的应用。因为Kestrel不支持在多进程间分享同一端口,所以应用并不能直接和Kestrel合作。当你在某个端口上配置Kestrel运行侦听时,不算主机头如何标识,Kestrel会为该端口处理所有的流量。反向代理可以为多个应用共享唯一端口并将流量发送给Kestrel。 即使不需要反向代理服务器,使用它也可以简化负载均衡和SSL设置 — 只要你的反向代理服务器需要SSL证书,并且该服务器可以和你的应用在内部网中通过普通HTTP进行通信。 如何在ASP.NET Core应用中使用Kestrel 安装 Microsoft.AspNetCore.Server.Kestrel Nuget包。 在应用的Main方法中调用WebHostBuilder的UseKestrel 扩展方法,指定你需要的Kestrel选项,如以下示例所示:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
public static int Main(string[] args) { Console.WriteLine("Running demo with Kestrel."); var config = new ConfigurationBuilder() .AddCommandLine(args) .Build(); var builder = new WebHostBuilder() .UseContentRoot(Directory.GetCurrentDirectory()) .UseConfiguration(config) .UseStartup<Startup>() .UseKestrel(options => { if (config["threadCount"] != null) { options.ThreadCount = int.Parse(config["threadCount"]); } }) .UseUrls("http://localhost:5000"); var host = builder.Build(); host.Run(); return 0; } |
URL 前缀 默认情况下,ASP.NET Core项目绑定了http://localhost:5000。通过使用UseUrls扩展方法——编辑urls命令行参数,或者是通过ASP.NET Core配置系统,你可以为Ketrel配置URL前缀和端口号以用来侦听请求。关于这些方法更多的信息,请参考Hosting。有关于当你使用IIS作为反向代理时,URL绑定是如何工作的信息,请参考ASP.NET Core 模块。 Kestrel URL前缀可以是以下格式中的任一种。 IPv4 地址和端口号
|
1 2 |
http://65.55.39.10:80/ https://65.55.39.10:443/ |
IPv6 地址和端口号
|
1 2 |
http://[0:0:0:0:0:ffff:4137:270a]:80/ https://[0:0:0:0:0:ffff:4137:270a]:443/ |
IPv6中的 [::] 等价于 IPv4 0.0.0.0。 主机名和端口号
|
1 2 3 4 |
http://contoso.com:80/ http://*:80/ https://contoso.com:443/ https://*:443/ |
主机名称,*,以及+,都不是特殊的。任何没有公认的IP 或是“localhost”的地址将绑定到所有的IPv4和IPv6的IP上。如果你需要为不同的ASP.NET Core应用在同一端口上绑定不同的主机名,请使用WebListener或者诸如IIS,Nginx或Apache这样的反向代理服务器。 * "Localhost" 名称和端口号或回送IP地址和端口号
|
1 2 3 |
http://localhost:5000/ http://127.0.0.1:5000/ http://[::1]:5000/ |
当localhost被指定时,Kestrel会尝试去绑定到IPv4和IPv6的环回接口。如果被请求的端口号正在任一环回接口上被其他服务所使用,Kestrel将会启动失败。如果任一环回接口出于各种原因而不可用(最通常的情况是因为IPv6暂不被支持),Kestrel将记录下一个警告信息。 Unix socket
|
1 |
http://unix:/run/dan-live.sock |
如果你指定了端口号0,Kestrel将动态地绑定到合适的端口号。除了localhost名称,绑定到0端口号被其他任何主机名称或IP地址所允许。 当你指定了端口号0,你可以使用IServerAddressesFeature接口去决定运行时Kestrel实际绑定到哪个端口。下列示例用于获取绑定端口并且在console上显示出来。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(); var serverAddressesFeature = app.ServerFeatures.Get<IServerAddressesFeature>(); app.UseStaticFiles(); app.Run(async (context) => { context.Response.ContentType = "text/html"; await context.Response .WriteAsync("<p>Hosted by Kestrel</p>"); if (serverAddressesFeature != null) { await context.Response .WriteAsync("<p>Listening on the following addresses: " + string.Join(", ", serverAddressesFeature.Addresses) + "</p>"); } await context.Response.WriteAsync($"<p>Request URL: {context.Request.GetDisplayUrl()}<p>"); }); } |
SSL的URL前缀 如果你调用UseSSL扩展方法,请确保在https:中包含URL前缀,如下所示:
|
1 2 3 4 5 6 7 8 9 |
var host = new WebHostBuilder() .UseKestrel(options => { options.UseHttps("testCert.pfx", "testPassword"); }) .UseUrls("http://localhost:5000", "https://localhost:5001") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>() .Build(); |
Note HTTPS和HTTP不能在同一端口上被托管。 下一步 更多的信息,请参考以下资源: Sample app for this […]
View Details1、首先打开php.ini文件,修改post_max_size设定POST数据所允许的最大限制值,php中默认post_max_size=2M;在php.in文件中按Ctrl+F,然后输入post_max_size,找到post_max_size将其改为自己需要上传限制文件的大小,比如改为post_max_size=300M; 2、修改完之后并不能上传较大的文件,则继续修改php.ini中的参数upload_max_filesize,其表示为上传文件的最大值。默认值upload_max_filesize=8M,修改为upload_max_filesize=300M; 3、如果上传仍然有问题,则继续修改。可能跟上传时间有关系。找到php.ini文件中的max_execution_time,默认值max_execution_time=30,其意思就是该页面最长执行的时间为30s,30s之后则上传停止,从而导致上传失败。修改为max_execution_time=0;0表示没有限制。 附: 另外要注意的是,post_max_size 应该大于upload_max_filesize 。 from:https://blog.csdn.net/rision666/article/details/51590803
View Details控制反转:我们向IOC容器发出获取一个对象实例的一个请求,IOC容器便把这个对象实例“注入”到我们的手中,在这个过程中你不是一个控制者而是一个请求者,依赖于容器提供给你的资源,控制权落到了容器身上。这个过程就是控制反转。 依赖注入:我们向容器发出请求以后,获得这个对象实例的过程就叫依赖注入。 IoC模式其实是工厂设计模式的升华,在微软较早的PetShop项目通过反射技术做了很多工厂。我认为可能是IoC的原型。 关于Ioc的框架有很多,比如Castle Windsor、Unity、Spring.NET、StructureMap,我们这边使用微软提供的Unity做示例,你可以使用 Nuget 添加 Unity ,也可以引用Microsoft.Practices.Unity.dll和Microsoft.Practices.Unity.Configuration.dll,下面我们就一步一步的学习下 Unity依赖注入 的详细使用。 Unity是微软推出的IOC框架, 使用这个框架,可以实现AOP面向切面编程,便于代码的后期维护,此外,这套框架还自带单例模式,可以提高程序的运行效率。 下面是我自己的案例,以供日后参考: 使用VS2015的Nuget管理器下载Unity。 程序员接口类:
|
1 2 3 4 5 6 7 |
namespace UnityDemo { public interface IProgrammer { void Working(); } } |
程序员类:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using System; namespace UnityDemo { public class CSharp : IProgrammer { public void Working() { Console.WriteLine("programming C# ..."); } } public class VB : IProgrammer { public void Working() { Console.WriteLine("programming VB ..."); } } public class Java : IProgrammer { public void Working() { Console.WriteLine("programming Java ..."); } } } |
App.config配置文件:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?> <configuration> <!--<startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/> </startup>--> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/> </configSections> <unity> <containers> <container name="Programmer"> <register type="UnityDemo.IProgrammer,UnityDemo" mapTo="UnityDemo.CSharp,UnityDemo" name="CSharp"></register> <register type="UnityDemo.IProgrammer,UnityDemo" mapTo="UnityDemo.VB,UnityDemo" name="VB"></register> <register type="UnityDemo.IProgrammer,UnityDemo" mapTo="UnityDemo.Java,UnityDemo" name="Java"></register> </container> </containers> </unity> </configuration> |
主程序代码:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.Configuration; using System; using System.Configuration; namespace UnityDemo { class Program { private static IUnityContainer container = null; static void Main(string[] args) { RegisterContainer(); var programmer = container.Resolve<IProgrammer>("CSharp"); //var programmer = container.Resolve<IProgrammer>("VB"); programmer.Working(); Console.ReadKey(); } private static void RegisterContainer() { container = new UnityContainer(); UnityConfigurationSection config =(UnityConfigurationSection) ConfigurationManager.GetSection(UnityConfigurationSection.SectionName); config.Configure(container, "Programmer"); } } } |
运行结果: 这个Demo的思想: 定义一个程序员接口IProgrammer,有3个实现这个接口的程序员类,分别是CSharp、VB、Java, 然后配置App.config文件,里面首先定义一个配置节点(configSection),名称为Unity,引用的命名空间是微软的Unity, 接着下面定义一个unity节点,里面的容器集合(containers),集合里面可以有多个容器,这个Demo里的只有一个容器,里面包含了3个注册节点(register),分别是CSharp,VB、Java,注意,里节点中的name属性用于在程序调用时选择类的。 在主程序的代码中, 1、有一个Unity的容器container; 2、注册容器的方法RegisterContainer,作用是到App.config中读取容器的信息,把接口和3个类的映射关系注册到容器中; 3、主程序运行前,先注册容器,然后通过容器的Resolve方法,实例化一个programmer类,原理大概是,我们把类名传入到容器中,容器会根据类名,找到App.config中对应的register映射关系,容器就会通过反射得到相应的程序员类,返回这个类。 4、此时programmer类就实例化完成,可以使用了。 使用了Unity,以后如果需要追加新的类,只需要实现IProgrammer接口,在配置文件追加映射关系,执行代码中修改name的值就能使用新的类了。 这样,我们不需要删除旧的代码,就能追加新的功能,便于维护代码。 本人的Demo下载 转自: https://www.cnblogs.com/chenyucong/p/6272600.html
View Details官网生成的ABP + module zero出现Default language is not defined!的错误,原因是数据库没有language数据,而不是缺少language.xml资源文件,所以先创建数据库就好了。 解决方法: 1.选择Web项目作为起始项目。 2.打开程序包管理控制台,选择“EntityFramework”项目作为默认项目,然后运行EF的’Update-Database’命令。该命令会创建数据库。 3.运行该应用,默认的用户名是’admin’,密码是’123qwe’。 在执行第2步时遇到了如下错误: Update-Database : 无法将“Update-Database”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后重试。 原因可能是EntityFramework没有安装,Install-Package EntityFramework就好了。什么?还是不行?全部重新生成再重新打开vs试试吧! https://blog.csdn.net/klo220/article/details/51138582
View DetailsGradle是一个基于Apache Ant和Apache Maven概念的项目自动化构建工具。它使用一种基于Groovy的特定领域语言(DSL)来声明项目设置,抛弃了基于XML的各种繁琐配置。 面向Java应用为主。当前其支持的语言限于Java、Groovy、Kotlin和Scala,计划未来将支持更多的语言。
View Details测试文件 test.php <?php echo "hello world."; ?> 1.加密方法: <?php /* eval() 函数把字符串按照 PHP 代码来计算。该字符串必须是合法的 PHP 代码,且必须以分号结尾。 strtr() 字符替换 把字符串中的字符 "ia" 替换为 "eo":strtr("Hilla Warld","ia","eo"); */ function T_rndstr($length = "") { //返回随机字符串 $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; if ($length == "") { return str_shuffle($str); } else { return substr(str_shuffle($str), -$length); } } $T_k1 = T_rndstr(); //随机密匙1 $T_k2 = T_rndstr(); //随机密匙2 $vstr = file_get_contents("./test.php"); //要加密的文件 $v1 = base64_encode($vstr); $c = strtr($v1, $T_k1, $T_k2); //根据密匙替换对应字符 $c = $T_k1 . $T_k2 . $c; //$qn变量功能下面会讲解 $isqs = 3; if ($isqs == "1") { // 1 取随机字符串为变量名 […]
View Details方法一、简单安装(通过yum) 1.安装epel-release rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm 2.安装PHP7的rpm源 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 3.安装PHP7 yum install php70w 方法二、编译安装 1.下载php7 wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror 2.解压php7 tar -xvf php7.tar.gz 3.进入php目录 cd php-7.0.4 4.安装依赖包 # 直接复制下面一行(不包括本行) yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel 5.编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致) 嫌麻烦的可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc \ --enable-fpm \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mcrypt \ --with-mhash \ --with-pcre-regex \ --with-sqlite3 \ --with-zlib \ --enable-bcmath \ --with-iconv \ --with-bz2 \ --enable-calendar \ --with-curl \ --with-cdb \ --enable-dom \ --enable-exif \ --enable-fileinfo \ --enable-filter \ --with-pcre-dir \ --enable-ftp \ --with-gd \ --with-openssl-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib-dir \ --with-freetype-dir \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --with-onig \ --enable-pdo \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-zlib-dir \ --with-pdo-sqlite \ --with-readline \ --enable-session \ --enable-shmop \ --enable-simplexml \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-libxml-dir \ --with-xsl \ --enable-zip \ --enable-mysqlnd-compression-support \ --with-pear \ --enable-opcache |
6.正式安装 make && make install 7.配置环境变量 vi /etc/profile 在末尾追加 PATH=$PATH:/usr/local/php/bin export PATH 执行命令使得改动立即生效 source /etc/profile 8.配置php-fpm
|
1 2 3 4 5 |
cp php.ini-production /etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm |
9.启动php-fpm /etc/init.d/php-fpm start 以上所述是小编给大家介绍的Centos7 安装 PHP7最新版的详细教程,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持! […]
View Details还没安装 Composer 吗?请往下看如何安装 Composer 。 镜像用法 有两种方式启用本镜像服务: 系统全局配置: 即将配置信息添加到 Composer 的全局配置文件 config.json 中。见“方法一” 单个项目配置: 将配置信息添加到某个项目的 composer.json 文件中。见“方法二” 方法一: 修改 composer 的全局配置文件(推荐方式) 打开命令行窗口(windows用户)或控制台(Linux、Mac 用户)并执行如下命令: 复制
|
1 2 |
composer config -g repo.packagist composer https://packagist.phpcomposer.com |
方法二: 修改当前项目的 composer.json 配置文件: 打开命令行窗口(windows用户)或控制台(Linux、Mac 用户),进入你的项目的根目录(也就是 composer.json 文件所在目录),执行如下命令: 复制
|
1 2 |
composer config repo.packagist composer https://packagist.phpcomposer.com |
上述命令将会在当前项目中的 composer.json 文件的末尾自动添加镜像的配置信息(你也可以自己手工添加): 复制
|
1 2 3 4 5 6 7 |
"repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } } |
以 laravel 项目的 composer.json 配置文件为例,执行上述命令后如下所示(注意最后几行): 复制
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.5.9", "laravel/framework": "5.2.*" }, "config": { "preferred-install": "dist" }, "repositories": { "packagist": { "type": "composer", "url": "https://packagist.phpcomposer.com" } } } |
OK,一切搞定!试一下 composer install 来体验飞一般的速度吧! 镜像原理: 一般情况下,安装包的数据(主要是 zip 文件)一般是从 github.com 上下载的,安装包的元数据是从 packagist.org 上下载的。 然而,由于众所周知的原因,国外的网站连接速度很慢,并且随时可能被“墙”甚至“不存在”。 “Packagist 中国全量镜像”所做的就是缓存所有安装包和元数据到国内的机房并通过国内的 CDN 进行加速,这样就不必再去向国外的网站发起请求,从而达到加速 composer install以及 composer update 的过程,并且更加快速、稳定。因此,即使 packagist.org、github.com 发生故障(主要是连接速度太慢和被墙),你仍然可以下载、更新安装包。 from:https://pkg.phpcomposer.com
View Detailspost提交数据时候显示如下:
|
1 2 3 |
The page <span class="hljs-keyword">has</span> expired due <span class="hljs-keyword">to</span> inactivity. Please refresh <span class="hljs-keyword">and</span> <span class="hljs-keyword">try</span> again |
这是由于在laravel框架中有此要求:任何指向 web 中 POST, PUT 或 DELETE 路由的 HTML 表单请求都应该包含一个 CSRF 令牌,否则,这个请求将会被拒绝。 eg:
|
1 2 3 4 5 6 |
<form method=<span class="hljs-string">"POST"</span> action=<span class="hljs-string">"/profile"</span>> {{ csrf_field() }} <span class="hljs-keyword">...</span> </form> |
from:http://blog.csdn.net/wuyoulv/article/details/78139632
View Detailserror_reporting的14个级别: E_ALL 所有错误和警告 E_COMPILE_ERROR 致命的编译时错误 E_COMPILE_WARNING 编译时警告 E_CORE_ERROR PHP开始启动时发生的致命错误 E_CORE_WARNING PHP开始启动时发生的警告 E_ERROR 致命的运行时错误 E_NOTICE 运行时注意消息 E_PARSE 编译时解析错误 E_RECOVERABLE_ERROR E_STRICT PHP版本可移植性建议(PHP5.0中引入) E_USER_ERROR 用户导致的错误 E_USER_NOTICE 用户导致的注意消息 E_USER_WARNING 用户导致的警告 E_WARNING 运行时警告
View Details