nginx

【学相伴】Nginx最新教程通俗易懂-狂神说

£可爱£侵袭症+ 提交于 2021-01-30 12:38:07
Nginx - 学相伴 分享人:秦疆(遇见狂神说) 公司产品出现瓶颈? 我们公司项目刚刚上线的时候,并发量小,用户使用的少,所以在低并发的情况下,一个jar包启动应用就够了,然后内部tomcat返回内容给用户。 但是慢慢的,使用我们平台的用户越来越多了,并发量慢慢增大了,这时候一台服务器满足不了我们的需求了。 于是我们横向扩展,又增加了服务器。这个时候几个项目启动在不同的服务器上,用户要访问,就需要增加一个代理服务器了,通过代理服务器来帮我们转发和处理请求。 我们希望这个代理服务器可以帮助我们接收用户的请求,然后将用户的请求按照规则帮我们转发到不同的服务器节点之上。这个过程用户是无感知的,用户并不知道是哪个服务器返回的结果,我们还希望他可以按照服务器的性能提供不同的权重选择。保证最佳体验!所以我们使用了Nginx。 什么是Nginx? Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。2011年6月1日,nginx 1.0.4发布。 其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好

Nginx负载均衡

孤者浪人 提交于 2021-01-30 09:52:30
Nginx负载均衡 Nginx(反向代理服务器) 正向代理 场景:在国内是无法正常使用google.com。如果想要访问google.com,可以购买一台国外的服务器A,此时你和服务器A的网络是相通的。而服务器A又跟google.com相通, 此时可以由服务器A代理你(客户端),去访问google.com。这个过程称之为正向代理,服务端(google.com)只需要知道代理服务器的ip,不需要知道客户端的ip。 示例1: 示例2: 结论:正向代理,是用于代理客户端的。 反向代理 场景:当一个服务器接受过多来自客户端的请求时,服务器难以处理和响应这些请求,会使得整个系统性能下降。为了解决这个难题,可以提供多台部署相同应用的服务器,让客户端的请求分别发送到不同的服务器上,这样单机服务器的压力就会降低很多,整体性能便会提升。但是有一个问题,每个服务器ip都是不同的,也就是说客户端的请求要发送到多个不同的ip上。让客户手动指定ip进行请求,这种方式很不明智。首先是客户的随机性,不知道会访问哪台服务器,其次,会造成一部分服务器压力大,一部分服务器几乎没有使用,浪费资源。因此,这里就需要一个角色去代理服务器,让客户端的请求直接发送到这个角色上,由这个角色去分发请求到不同的服务器上。 这个角色就是反向代理服务器。 结论:反向代理,是用于代理服务端的。 负载均衡 场景:反向代理过程中

Waiting (TTFB) 时间

杀马特。学长 韩版系。学妹 提交于 2021-01-30 09:42:24
什么是 Waiting (TTFB) 时间 TTFB 是 Time to First Byte 的缩写,指的是浏览器开始收到服务器响应数据的时间(后台处理时间+重定向时间),是反映服务端响应速度的重要指标。就像你问朋友了一个问题,你的朋友思考了一会儿才给你答案,你朋友思考的时间就相当于 TTFB。你朋友思考的时间越短,就说明你朋友越聪明或者对你的问题越熟悉。对服务器来说,TTFB 时间越短,就说明服务器响应越快。 TTFB 时间多长算长? 因为每个服务器的硬件和网络环境都不尽相同,每个服务器的 TTFB 时间也不相同。如果想知道你的服务器可以优化到什么程度,大家可以上传一些静态的 HTML 页面到服务器,然后打开这些静态页面,看一些这些页面的 TTFB 时间,大多数服务器的 TTFB 时间都在 50 ms 一下,这个时间就是我们优化时候可以追求的时间。下面两个图中的 TTFB 时间分别是本站所在服务器的静态和动态网页 TTFB 等待时间。 根据我们的测试,TTFB 时间如果超过了 500 ms,用户在打开网页的时候就会感觉到明显的等待。我么可以把 500 ms 以上认为是 TTFB 时间过长。可见,WordPress 智库的服务器还不算差。 TTFB 过长的原因 我们知道,对于动态网页来说,服务器收到用户打开一个页面的请求时,首先要从数据库中读取该页面需要的数据

CompletableFuture.supplyAsync

时光毁灭记忆、已成空白 提交于 2021-01-30 01:16:09
记一次CompletableFuture.supplyAsync 的使用遇到的问题 背景: 平时我们的接口方法响应不会时间太长,nginx或者后端框架都会有默认接口响应时间,超时后熔断,返回默认值,或者默认错误的设置。 需求: 千万级的表数据关联,要求按一些纬度分组后求值,推送至第三方系统,要求是前端点按钮触发,这里防重机制后面再说。 开发: 查询性能优化索引查询语句等后,从三分多钟优化到一分40秒,接口正常,前端仍然pending过后,404熔断,这样级别调高响应时间也不是长久之计,于是改为异步执行,接口直接返回结果。 于是找到了CompletableFuture.supplyAsync(x->())这个方法,如下写完后,死活进不了异步方法里面: ` @RestController @RequestMapping(value = "/task") public class SyncTask { @PostMapping(value = "/sync") public String testSync() throws InterruptedException { // 开启异步任务执行任务 CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { try { System.out.println

nginx负载均衡

笑着哭i 提交于 2021-01-29 23:57:35
nginx负载均衡 负载均衡建立在现有网络结构之上,提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽,增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性。 随着网站的发展,服务器压力越来越大,我们可能首先会将数据库,静态文件分离出去。但是随着发展,单独业务API的请求的压力也会变得很大,这时候我们可能需要做负载均衡将一台服务器面临的压力分散到多台服务器上。 nginx 不仅可以作为强大的web服务器,也可以作为反向代理服务器,而且nginx还可以按照调度规则实现动静分离,还可以对后端的服务器做负载均衡。 nginx负载均衡配置 nginx的负载均衡主要是对proxy_pass和upstream的配置。 我们首先需要建立一个Spring Boot的项目对外提供服务,来模拟我们实际的服务,还可以配置其它可以提供网络请求处理的框架来提供服务,这里具体由什么来提供服务和nginx配置并不相关。 Spring Boot 项目建立的过程就不提了,这里只贴一下主要的代码: import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

How to install SSL certificate text on Ubuntu nginx

↘锁芯ラ 提交于 2021-01-29 19:21:17
问题 I am running a Ubuntu 18.04 server on AWS Lightsail, using nginx. I have a purchased SSL certificate for my domain name through the domain registrar (domain.com) - I can download the 'certificate' and the 'key' as long strings of text characters/symbols. How do I then 'install' this SSL certificate onto my Nginx server? 回答1: There are two files that must be configured on the Nginx server, the certificate .crt and the certificate key .key , you simply have to have these 2 files on your Nginx

Can't start the laravel-websockets admin page

给你一囗甜甜゛ 提交于 2021-01-29 18:26:03
问题 I have the demo laravel websockets app up and running on a centos server, having followed the basic installation instructions here: https://github.com/beyondcode/laravel-websockets-demo I've also got it set up and running in Nginx (so am not running php artisan serve) However, I can't get the php artisan websockets:serve command to work. on the cli it says: "Starting the WebSocket server on port 6001..." And I can get into mydomain/laravel-websockets and see the admin console, but it can't

PHP Fatal error : Call to undefined function mysql_connect()

爱⌒轻易说出口 提交于 2021-01-29 18:02:11
问题 I have recently installed PHP 7.0.8 (ZTS) on CentOS 7 with the following configuration: --prefix=/usr/local/php7 \ --with-config-file-scan-dir=/usr/local/php7/etc/conf.d \ --enable-bcmath \ --enable-calendar \ --enable-exif \ --enable-opcache --enable-dba \ --enable-ftp \ --with-gettext \ --with-gd \ --with-jpeg-dir \ --enable-mbstring \ --with-mcrypt \ --with-mhash \ --enable-mysqlnd \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-mysql-sock=/var/run/mysqld

Matching specific host name and redirecting to www.myhostname.com/some-extra-path, not affecting other hostnames

柔情痞子 提交于 2021-01-29 14:29:15
问题 I'm having no luck googling this, maybe because I'm using the wrong terminology. Here are some examples to clarify the behavior I'm looking for: Redirects for hostname- two .com -> hostname- two .com/sub-folder No re-directs for hostname- two .com/something (URL already ok url) hostname-two.com/sub-folder (URL already ok url) hostname-two.com/sub-folder/something (URL already ok url) hostname-one.com (hostname- one should not be affected) hostname-one.com/something (hostname- one should not

Why does assembly of Vagrant and Xdebug not works on latest versions of PHP?

风格不统一 提交于 2021-01-29 14:08:02
问题 I have the working assembly of vagrant + nginx + PHP + xdebug. Everything is ok while the PHP version is 7.0, but when I upgrade PHP to 7.2 or 7.4 Xdebug stop works. Xdebug installed the latest version (3.0.1). Vagrantfile (part): sudo add-apt-repository -y ppa:ondrej/php sudo add-apt-repository -y ppa:ondrej/nginx sudo apt-get update sudo apt-get install -y nginx sudo apt-get install -y php7.0-fpm php7.0-xdebug sudo service php7.0-fpm stop sudo cp /vagrant/.provision/xdebug.ini /etc/php/7.0