nginx做调度(自身用dns轮询保证高可用),varnish做后端的cache

2024-04-26 15:38

本文主要是介绍nginx做调度(自身用dns轮询保证高可用),varnish做后端的cache,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Nginx + varnish 构建高可用CDN节点集群

作者:随风 发布于:2012-6-19 10:29 Tuesday 分类:linux运维

OSAPUB 出品的集群方案,旨在抛砖引玉,给广大朋友提供高可用CDN节点集群方案
转载请标明出去:http://bbs.osapub.com/thread-3370-1-1.html

一、        环境描述

Linux server A  (CentOS release 5.8 Final)  实IP:192.168.4.97  虚IP:192.168.4.96
Linux server B  (CentOS release 5.8 Final)  实IP:192.168.4.99  虚IP:192.168.4.98

域名环境(DNS轮询解析到虚IP):
server.osapub.com 192.168.4.96
server.osapub.com 192.168.4.98

二、        简单架构示意图
22.jpg
描述:前端两台NGINX做DNS轮询,通过虚IP漂移+HA监控脚本相结合,实现前端两台NGINX高可用,利用NGINX反向代理功能对后端varnish实现高可用集群。

三、软件环境搭建
3.1 编译安装nginx

001?
002#!/bin/bash
003####nginx 环境安装脚本,注意环境不同可能导致脚本运行出错,如果环境不同建议手工一条一条执行指令。
004 
005#创建工作目录
006mkdir -p /dist/{dist,src}
007cd /dist/dist
008 
009#下载安装包
010wget http://bbs.osapub.com/down/google-perftools-1.8.3.tar.gz &> /dev/null
011wget http://bbs.osapub.com/down/libunwind-0.99.tar.gz &> /dev/null
012wget http://bbs.osapub.com/down/pcre-8.01.tar.gz &> /dev/null
013wget http://bbs.osapub.com/down/nginx-1.0.5.tar.gz &> /dev/null
014 
015#------------------------------------------------------------------------
016# 使用Google的开源TCMalloc库,忧化性能
017 
018cd /dist/src
019tar zxf ../dist/libunwind-0.99.tar.gz
020cd libunwind-0.99/
021 
022## 注意这里不能加其它 CFLAGS加速编译参数
023 
024CFLAGS=-fPIC ./configure
025make clean
026make CFLAGS=-fPIC
027make CFLAGS=-fPIC install
028if [ "$?" == "0" ]; then
029        echo "libunwind-0.99安装成功." >> ./install_log.txt
030else
031        echo "libunwind-0.99安装失败." >> ./install_log.txt
032        exit 1
033fi
034 
035##----------------------------------------------------------
036## 使用Google的开源TCMalloc库,提高MySQL在高并发情况下的性能
037 
038cd /dist/src
039tar zxf ../dist/google-perftools-1.8.3.tar.gz
040cd google-perftools-1.8.3/
041 
042CHOST="x86_64-pc-linux-gnu" CFLAGS="-march=nocona -O2 -pipe" CXXFLAGS="-march=nocona -O2 -pipe" \
043./configure
044 
045make clean
046make && make install
047if [ "$?" == "0" ]; then
048        echo "google-perftools-1.8.3安装成功." >> ./install_log.txt
049else
050        echo "google-perftools-1.8.3安装失败." >> ./install_log.txt
051        exit 1
052fi
053 
054echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
055/sbin/ldconfig
056 
057################ 安装nginx ##########################
058#安装Nginx所需的pcre库
059 
060cd /dist/src
061tar zxvf ../dist/pcre-8.01.tar.gz
062cd pcre-8.01/
063 
064CHOST="x86_64-pc-linux-gnu" CFLAGS="-march=nocona -O2 -pipe" CXXFLAGS="-march=nocona -O2 -pipe" \
065./configure
066make && make install
067if [ "$?" == "0" ]; then
068        echo "pcre-8.01安装成功." >> ./install_log.txt
069else
070        echo "pcre-8.01安装失败." >> ./install_log.txt
071        exit 1
072fi
073cd ../
074 
075## 安装Nginx
076## 为优化性能,可以安装 google 的 tcmalloc ,之前己经安装过了
077## 所以我们编译 Nginx 时,加上参数 --with-google_perftools_module
078## 然后在启动nginx前需要设置环境变量 export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
079## 加上 -O2 参数也能优化一些性能
080##
081## 默认的Nginx编译选项里居然是用 debug模式的(-g参数),在 auto/cc/gcc 文件最底下,去掉那个 -g 参数
082## 就是将  CFLAGS="$CFLAGS -g"  修改为   CFLAGS="$CFLAGS"   或者直接删除这一行
083 
084cd /dist/src
085rm -rf nginx-1.0.5
086tar zxf ../dist/nginx-1.0.5.tar.gz
087cd nginx-1.0.5/
088 
089sed -i 's#CFLAGS="$CFLAGS -g"#CFLAGS="$CFLAGS "#' auto/cc/gcc
090 
091make clean
092 
093CHOST="x86_64-pc-linux-gnu" CFLAGS="-march=nocona -O2 -pipe" CXXFLAGS="-march=nocona -O2 -pipe" \
094./configure --user=www --group=www \
095--prefix=/usr/local/nginx \
096--with-http_stub_status_module \
097--with-google_perftools_module
098 
099make && make install
100if [ "$?" == "0" ]; then
101        echo "nginx-1.0.5安装成功." >> ./install_log.txt
102else
103        echo "nginx-1.0.5安装失败." >> ./install_log.txt
104        exit 1
105fi
106cd ../
107 
108#创建Nginx日志目录
109mkdir -p /data/logs
110chmod +w /data/logs
111chown -R www:www /data/logs
112 
113cd /usr/local/nginx/
114mv conf conf_bak
115ln -s /data/conf/nginx/ conf
116 
117echo 'export LD_PRELOAD=/usr/local/lib/libtcmalloc.so' > /root/nginx_start
118echo 'ulimit -SHn 51200' >> /root/nginx_start
119echo '/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf' >> /root/nginx_start
120 
121echo '/usr/local/nginx/sbin/nginx -t' > /root/nginx_reload
122echo 'kill -HUP `cat /usr/local/nginx/logs/nginx.pid`' >> /root/nginx_reload
123 
124chmod 700 /root/nginx_*

3.2        编译安装varnish

01#!/bin/bash
02 
03#进入工作目录
04cd /dist/dist
05 
06#下载安装包
07wget <a href="\"http://bbs.osapub.com/down/varnish-3.0.0.tar.gz\"" target="\"_blank\"">http://bbs.osapub.com/down/varnish-3.0.0.tar.gz</a> &> /dev/null
08cd /dist/src
09rm -fr varnish-3.0.0
10export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
11tar zxvf ../dist/varnish-3.0.0.tar.gz
12cd varnish-3.0.0
13#编译参数可以根据自己需要定制
14./configure -prefix=/usr/local/varnish -enable-debugging-symbols -enable-developer-warnings -enable-dependency-tracking
15make && make install
16if [ "$?" == "0" ]; then
17        echo "varnish-3.0.0安装成功." >> ./install_log.txt
18else
19        echo "varnish-3.0.0安装失败." >> ./install_log.txt
20        exit 1
21fi
22 
23#设置启动、重启脚本
24cat > /root/varnish_restart.sh <<EOF
25#!/bin/bash
26pkill varnish
27pkill varnish
28ulimit -SHn 51200
29/usr/local/varnish/sbin/varnishd -n /data/varnish -f /usr/local/varnish/vcl.conf -a 0.0.0.0:81 -s malloc,12G -g www -u www -w 4000,12000,10 -T 127.0.0.1:3500 -p http_max_hdr=256 -p http_req_hdr_len=8192
30EOF
31 
32cat > /root/varnish_start.sh <<EOF
33#!/bin/bash
34ulimit -SHn 51200
35/usr/local/varnish/sbin/varnishd -n /data/varnish -f /usr/local/varnish/vcl.conf -a 0.0.0.0:81 -s malloc,12G -g www -u www -w 4000,12000,10 -T 127.0.0.1:3500 -p http_max_hdr=256 -p http_req_hdr_len=8192
36EOF
37 
38chmod 755 /root/varnish*


三、        配置varnish一些参数说明:
Backend servers
Varnish有后端(或称为源)服务器的概念。后端服务器是指Varnish提供加速服务的那台,通常提供内容。
第一件要做的事情是告诉Varnish,哪里能找到要加速的内容。
vcl_recv
vcl_recv是在请求开始时调用的。完成该子程序后,请求就被接收并解析了。用于确定是否需要服务请求,怎么服务,如果可用,使用哪个后端。
在vcl_recv中,你也可以修改请求。通常你可以修改cookie,或添加/移除请求头信息。
注意在vcl_recv中,只可以使用请求对象req。

vcl_fetch
vcl_fetch是在文档从后端被成功接收后调用的。通常用于调整响应头信息,触发ESI处理,万一请求失败就换个后端服务器。
在vcl_fecth中,你还可以使用请求对象req。还有个后端响应对象beresp。Beresp包含了后端的HTTP头信息。

varnish 3.X 配置参考文档:http://anykoro.sinaapp.com/?p=261

编辑:/usr/local/varnish/vcl.conf ,文件不存在则创建。注意:Server A 与server B 配置一致!

配置详情如下:

001?
002###########后台代理服务器########
003 
004backend server_osapub_com{
005        .host = "192.168.4.97";
006        .port = "82";
007}
008 
009acl purge {
010        "localhost";
011                "127.0.0.1";
012}
013 
014#############################################
015 
016sub vcl_recv {
017 
018     #################BAN##########################begin
019         if (req.request == "BAN") {
020                # Same ACL check as above:
021                if (!client.ip ~ purge) {
022                        error 405 "Not allowed.";
023                }
024                ban("req.http.host == " + req.http.host +
025                      "&& req.url == " + req.url);
026                error 200 "Ban added";
027        }
028     #################BAN##########################end
029 
030         ###############配置域名##################################
031          if(req.http.host ~ "^server.osapub.com" ||req.http.host ~ ".osapub.com" ) {
032 
033                #使用哪一组后台服务器
034                        set req.backend = server_osapub_com;
035 
036                }
037 
038                ##################################################
039 
040        if (req.restarts == 0) {
041        if (req.http.x-forwarded-for) {
042           set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
043         }
044         else {
045            set req.http.X-Forwarded-For = client.ip;
046         }
047     }
048 
049        if (req.http.Accept-Encoding) {
050        if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
051            remove req.http.Accept-Encoding;
052        } elsif (req.http.Accept-Encoding ~ "gzip") {
053            set req.http.Accept-Encoding = "gzip";}
054          elsif (req.http.Accept-Encoding ~ "deflate") {
055            set req.http.Accept-Encoding = "deflate";}
056        else {
057         remove req.http.Accept-Encoding;
058      }
059    }
060     if (req.http.Cache-Control ~ "no-cache") {
061         return (pass);
062     }
063     if (req.request != "GET" &&
064       req.request != "HEAD" &&
065       req.request != "PUT" &&
066       req.request != "POST" &&
067       req.request != "TRACE" &&
068       req.request != "OPTIONS" &&
069       req.request != "DELETE") {
070         return (pipe);
071     }
072 
073     if (req.request != "GET" && req.request != "HEAD") {
074                        return(pass);
075                }              
076 
077         if (req.http.Authorization || req.http.Cookie ||req.http.Authenticate) {
078                 return (pass);
079     }        
080 
081        if (req.request == "GET" && req.url ~ "(?i)\.php($|\?)"){
082                return (pass);
083             }
084 
085        if (req.url ~ "\.(css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
086                unset req.http.Cookie;
087        }           
088 
089        return (lookup);
090 
091}
092 
093sub vcl_fetch {
094 
095        set beresp.grace = 5m;
096 
097        if (beresp.status == 404 || beresp.status == 503 || beresp.status == 500 || beresp.status == 502) {
098                set beresp.http.X-Cacheable = "NO: beresp.status";
099                set beresp.http.X-Cacheable-status = beresp.status;
100                return (hit_for_pass);
101        }
102 
103        #决定哪些头不缓存
104 
105    if (req.url ~ "\.(php|shtml|asp|aspx|jsp|js|ashx)$") {
106                return (hit_for_pass);
107         }
108 
109        if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf)$") {
110                unset beresp.http.set-cookie;
111        }
112 
113        if (beresp.ttl <= 0s) {
114                set beresp.http.X-Cacheable = "NO: !beresp.cacheable";
115                return (hit_for_pass);
116        }
117        else {
118                unset beresp.http.expires;
119        }
120 
121        return (deliver);
122 
123}
124 
125sub vcl_deliver {
126 
127if (resp.http.magicmarker) {
128 
129     unset resp.http.magicmarker;
130 
131     set resp.http.age = "0";
132 }
133 
134# add cache hit data
135if (obj.hits > 0) {
136 
137   set resp.http.X-Cache = "HIT";
138   set resp.http.X-Cache-Hits = obj.hits;
139}
140else {
141     set resp.http.X-Cache = "MISS";
142}
143 
144# hidden some sensitive http header returning to client, when the cache server received from backend server response
145remove resp.http.X-Varnish;
146remove resp.http.Via;
147remove resp.http.Age;
148remove resp.http.X-Powered-By;
149remove resp.http.X-Drupal-Cache;
150 
151return (deliver);
152}
153 
154sub vcl_error {
155 
156 if (obj.status == 503 && req.restarts < 5) {
157   set obj.http.X-Restarts = req.restarts;
158   return (restart);
159 }
160 
161}
162 
163sub vcl_hit {
164 
165if (req.http.Cache-Control ~ "no-cache") {
166 
167  if (! (req.http.Via || req.http.User-Agent ~ "bot|MSIE")) {
168      set obj.ttl = 0s;
169      return (restart);
170   }
171}
172  return(deliver);
173}

配置完成后执行:/root/varnish_start.sh 如果启动成功则表示配置无误!
33.jpg

四、        配置nginx编辑: /usr/local/nginx/conf/nginx.conf ,nginx 的配置方法请参考网上文档资料。
Server A(192.168.4.97) nginx配置如下:
001?
002user  www www;
003worker_processes 16;
004error_log /logs/nginx/nginx_error.log crit;
005 
006#Specifies the value for maximum file descriptors that can be opened by this process.
007worker_rlimit_nofile 65500;
008 
009events
010{
011        use epoll;
012 
013        worker_connections 65500;
014}
015 
016http
017{
018        include       mime.types;
019        default_type  application/octet-stream;
020 
021        server_names_hash_bucket_size 128;
022        client_header_buffer_size 64k;
023        large_client_header_buffers 4 64k;
024        client_max_body_size 10m;
025 
026        server_tokens off;
027 
028        expires       1h;
029 
030        sendfile on;
031        tcp_nopush     on;
032        keepalive_timeout 60;
033        tcp_nodelay on;
034 
035    fastcgi_connect_timeout 200;
036    fastcgi_send_timeout 300;
037    fastcgi_read_timeout 600;
038    fastcgi_buffer_size 128k;
039    fastcgi_buffers 4 64k;
040    fastcgi_busy_buffers_size 128k;
041    fastcgi_temp_file_write_size 128k;
042    fastcgi_temp_path /dev/shm;
043        gzip on;
044        gzip_min_length  2048;
045        gzip_buffers     4 16k;
046        gzip_http_version 1.1;
047        gzip_types  text/plain  text/css  application/xml application/x-javascript ;
048 
049        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
050                          '$status $body_bytes_sent "$http_referer" '
051                          '"$http_user_agent" $http_x_forwarded_for';
052 
053#################  include  ###################
054 
055         upstream varnish_server {
056                server 127.0.0.1:81 weight=2 max_fails=3 fail_timeout=30s;
057                    server 192.168.4.99:81 weight=2 max_fails=3 fail_timeout=30s;
058                ip_hash;
059        }
060 
061                server
062        {
063                listen       80;
064                server_name  192.168.4.96 192.168.4.98;
065                             index index.html index.htm index.php index.aspx;
066                location /
067                {
068                        proxy_set_header   Host             $host;
069                        proxy_set_header   X-Real-IP        $remote_addr;
070                        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
071 
072                        proxy_connect_timeout 200;
073                        proxy_send_timeout 300;
074                        proxy_read_timeout 500;
075                        proxy_buffer_size 256k;
076                        proxy_buffers 4 128k;
077                        proxy_busy_buffers_size 256k;
078                        proxy_temp_file_write_size 256k;
079                        proxy_temp_path  /dev/shm;
080 
081                        proxy_pass  http://varnish_server;
082 
083                        expires off;
084 
085                        access_log  /logs/nginx/192.168.4.96.log  access;
086                }
087        }
088 
089                server
090        {
091              listen       82;
092              server_name  192.168.4.97;
093              index index.html index.htm index.php;
094              root  /data/web/awstats/www;
095 
096              location ~ .*\.php$
097              {
098                   include fcgi.conf;
099                   fastcgi_pass  127.0.0.1:10080;
100                   fastcgi_index index.php;
101                   expires off;
102              }
103              access_log  /logs/nginx/awstats.osapub.com.log  access;
104        }              
105 
106}

server B (192.168.4.99)配置如下:

001?
002user  www www;
003worker_processes 16;
004error_log /logs/nginx/nginx_error.log crit;
005 
006#Specifies the value for maximum file descriptors that can be opened by this process.
007worker_rlimit_nofile 65500;
008 
009events
010{
011        use epoll;
012 
013        worker_connections 65500;
014}
015 
016http
017{
018        include       mime.types;
019        default_type  application/octet-stream;
020 
021        server_names_hash_bucket_size 128;
022        client_header_buffer_size 64k;
023        large_client_header_buffers 4 64k;
024        client_max_body_size 10m;
025 
026        server_tokens off;
027 
028        expires       1h;
029 
030        sendfile on;
031        tcp_nopush     on;
032        keepalive_timeout 60;
033        tcp_nodelay on;
034 
035    fastcgi_connect_timeout 200;
036    fastcgi_send_timeout 300;
037    fastcgi_read_timeout 600;
038    fastcgi_buffer_size 128k;
039    fastcgi_buffers 4 64k;
040    fastcgi_busy_buffers_size 128k;
041    fastcgi_temp_file_write_size 128k;
042    fastcgi_temp_path /dev/shm;
043        gzip on;
044        gzip_min_length  2048;
045        gzip_buffers     4 16k;
046        gzip_http_version 1.1;
047        gzip_types  text/plain  text/css  application/xml application/x-javascript ;
048 
049        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
050                          '$status $body_bytes_sent "$http_referer" '
051                          '"$http_user_agent" $http_x_forwarded_for';
052 
053#################  include  ###################
054 
055         upstream varnish_server {
056                server 127.0.0.1:81 weight=2 max_fails=3 fail_timeout=30s;
057                    server 192.168.4.97:81 weight=2 max_fails=3 fail_timeout=30s;
058                ip_hash;
059        }
060 
061                server
062        {
063                listen       80;
064                server_name  192.168.4.96 192.168.4.98;
065                             index index.html index.htm index.php index.aspx;
066                location /
067                {
068                        proxy_set_header   Host             $host;
069                        proxy_set_header   X-Real-IP        $remote_addr;
070                        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
071 
072                        proxy_connect_timeout 200;
073                        proxy_send_timeout 300;
074                        proxy_read_timeout 500;
075                        proxy_buffer_size 256k;
076                        proxy_buffers 4 128k;
077                        proxy_busy_buffers_size 256k;
078                        proxy_temp_file_write_size 256k;
079                        proxy_temp_path  /dev/shm;
080 
081                        proxy_pass  http://varnish_server;
082 
083                        expires off;
084 
085                        access_log  /logs/nginx/192.168.4.98.log  access;
086                }
087        }
088 
089                server
090        {
091              listen       82;
092              server_name  192.168.4.99;
093              index index.html index.htm index.php;
094              root  /data/web/awstats/www;
095 
096              location ~ .*\.php$
097              {
098                   include fcgi.conf;
099                   fastcgi_pass  127.0.0.1:10080;
100                   fastcgi_index index.php;
101                   expires off;
102              }
103              access_log  /logs/nginx/awstats.osapub.com.log  access;
104        }              
105 
106}

启动nginx:
/root/nginx_start
启动正常会监听80,82端口!
五、        运行nginx ha脚本

server A 的脚本下载地址:http://bbs.osapub.com/down/server_a_ha.tar.gz
解压力后得到三个脚本:
nginx_watchdog.sh
nginxha.sh
nginx_ha1.sh

server B 的脚本下载地址:http://bbs.osapub.com/down/server_b_ha.tar.gz
解压力后得到三个脚本:
nginx_watchdog.sh
nginxha.sh
nginx_ha2.sh

注意:脚本建议放到:/data/sh/ha 目录下,否则需要修改nginxha.sh  里面的程序路径!

六、        测试1,测试之前先把nginx 负载去掉,可以在前面加#号暂时注释,只保留本机解析,确保测试结果准确。
44.jpg

2,修改本机host文件
添加:192.168.4.99 server.osapub.com 到末尾,保存后访问。
55.jpg

3,正常结果显示如下:
66.jpg

到这里整个架构基本能运行起来了,根据大家的实际需求,对配置文件进行调优,HA脚本也可以进一步调优,关于报警,请参考社区自动安装mutt报警的脚本!

这篇关于nginx做调度(自身用dns轮询保证高可用),varnish做后端的cache的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/937975

相关文章

Eureka高可用注册中心registered-replicas没有分布式注册中心

自己在学习过程中发现,如果Eureka挂掉了,其他的Client就跑不起来了,那既然是商业项目,还是要处理好这个问题,所以决定用《Spring Cloud微服务实战》(PDF版在全栈技术交流群中自行获取)中说的“高可用注册中心”。 一开始我yml的配置是这样的 server:port: 8761eureka:instance:hostname: 127.0.0.1client:fetch-r

【LinuxC语言】select轮询

文章目录 前言select函数详解selectfd_set类型一个小问题select函数使用步骤改进服务器代码select服务器示例代码 总结 前言 在Linux C语言编程中,我们经常需要处理多个I/O操作。然而,如果我们为每个I/O操作创建一个线程,那么当I/O操作数量增加时,线程管理将变得复杂且效率低下。这就是我们需要select轮询的地方。select是一种高效的I/

设置Nginx缓存策略

详细信息 Nginx服务器的缓存策略设置方法有两种:add_header或者expires。 1. add_header 1)语法:add_header name value。 2)默认值:none。 3)使用范围:http、server、location。 配置示例如下: add_header cache-control "max-age=86400";#设置缓存时间为1天。add

OSG学习:LOD、数据分页、动态调度

LOD(level of detail):是指根据物体模型的结点在显示环境中所处的位置和重要度,决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算。在OSG的场景结点组织结构中,专门提供了场景结点osg::LOD来表达不同的细节层次模型。其中,osg::LOD结点作为父节点,每个子节点作为一个细节层次,设置不同的视域,在不同的视域下显示相应的子节点。 数据分页:在城市

Docker Compose--安装Nginx--方法/实例

原文网址:Docker Compose--安装Nginx--方法/实例_IT利刃出鞘的博客-CSDN博客 简介 说明 本文介绍Docker Compose如何安装Nginx。 目录结构 ├── config│   ├── cert│   │   ├── xxx_bundle.pem│   │   └── xxx.key│   ├── conf.d│   └── nginx.co

nginx 8051#0: *4 recv() failed (104: Connection reset by peer) while reading response header from u

环境    php7   nginx1.8.0    nginx   报错  500  GATWAY网关错误 2017/08/28 10:45:42 [error] 7975#0: *333 recv() failed (104: Connection reset by peer) while reading response header from upstream, clien

nginx 504 Gateway Time-out

环境:PHP7.1,NGINX,Mysql 问题描述: 本地写了一个需要执行比较长时间的脚本,放到了php-fpm里面跑。用一个链接调用起这个脚本。发现第一次调用的时候,需要等比较久的时间,但是如果在执行期间再次请求这个链接。第二个请求的链接会返回504。甚至,直接在脚本最开始的地方中断都还是报 504. 但是如果请求其他链接,可以正常请求。 nginx 返回码、、 504 Gateway

linux匹配Nginx日志,某个字符开头和结尾的字符串

匹配 os=1 开头, &ip结尾的字符串 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ 存入日志。然后使用submit 前面和后面的值去掉,剩下就是需要的字符串。 cat 2018-06-07.log | egrep -o ‘os=1.*.&ip’ >log.log

nginx问题记录以及解决方法

问题描述: 打开多个nginx.exe 结果在任务管理器中不能结束该进程 解决办法: 以管理员的身份运行cmd 1、查看所有nginx.exe 进程 tasklist /fi "imagename eq nginx.exe" 2、结束这些进程 taskkill /fi "imagename eq nginx.exe" /f 问题描述: 配置前端项目路径然后就直接看本地项目路径的属

Nginx基础概念和常用操作

文章目录 1. 安装、启动、连接2. 快速尝试部署网站3. 配置文件1. nginx.conf全局配置事件模块HTTP 模块性能优化建议 2. default.conf`server` 块基本设置日志设置根路径设置 4. 反向代理1. 模拟3个Web2. 链接 5. 负载均衡1. 加权轮询,Weighted Round Robin2. 最少连接,Least Connections3. I