-
Notifications
You must be signed in to change notification settings - Fork 41
/
use_swoole_or_fpm_depending_on_clients.conf
107 lines (86 loc) · 3.35 KB
/
use_swoole_or_fpm_depending_on_clients.conf
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
upstream default {
server 127.0.0.1:9501 weight=1 max_fails=1 fail_timeout=10 ;
server 127.0.0.1:81 backup;
# The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
# It does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
# https://gist.github.com/magnetikonline/4a2e68b2ce94bd0c945e
# https://ma.ttias.be/enable-keepalive-connections-in-nginx-upstream-proxy-configurations/
keepalive 8;
}
upstream swoole {
server 127.0.0.1:9501;
}
upstream fpm {
server 127.0.0.1:81;
}
# map to different upstream backends based on query parameter 'useserver'
# visit http://fly.test/?useserver=swoole to use server swoole
# visit http://fly.test to use upstream default
map $arg_useserver $pool {
default "default";
swoole "swoole";
fpm "fpm";
}
log_format my_upstream '$remote_addr|$time_local|$request_time|$upstream_response_time|$status '
'$upstream_addr|$request';
server {
server_name fly.test;
listen 80;
root /www/fly/public;
index index.html;
charset utf-8;
location = / {
# if you have a static home page , try this one:
# try_files index.html @other;
try_files '' @php;
}
location / {
try_files $uri $uri/ @php;
}
location @php {
proxy_pass http://$pool;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
# Remove the Connection header if the client sends it,
# it could be "close" to close a keepalive connection
proxy_set_header Connection "";
# proxy_connect_timeout 60s;
# proxy_send_timeout 60s;
# proxy_read_timeout 120s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# proxy_set_header X-Real-PORT $remote_port;
# proxy_set_header Scheme $scheme;
# proxy_set_header Server-Protocol $server_protocol;
# proxy_set_header Server-Name $server_name;
# proxy_set_header Server-Addr $server_addr;
# proxy_set_header Server-Port $server_port;
# just a mark for different upstream server, you can disable it
add_header X-Upstream $upstream_addr;
# log
access_log /var/log/nginx/upstream.log my_upstream;
}
# # only for Let's Encrypt
# location ~ /.well-known {
# allow all;
# # set root is necessage, otherwise "Invalid response from domain..."
# # https://www.digitalocean.com/community/questions/letsencrypt-problem-renewing-certs-invalid-response-from-domain
# root {{ doc_root }};
# }
}
server {
server_name fly.test;
listen 81;
root /vagrant/www/zc/public;
index index.html index.php;
charset utf-8;
location / {
try_files '' /index.php?$query_string;
}
location /index.php {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}