-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathnginx-install.sh
More file actions
122 lines (104 loc) · 3.68 KB
/
nginx-install.sh
File metadata and controls
122 lines (104 loc) · 3.68 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
yum install -y wget
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
groupadd nginx
useradd -r -g nginx nginx -s /sbin/nologin
yum install -y gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel
if [ -d nginx-1.14.2 ]; then
echo "nginx folder is exists"
else
tar -xzvf nginx-1.14.2.tar.gz
fi
cd nginx-1.14.2 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre --with-http_stub_status_module --with-http_realip_module --with-http_gzip_static_module --with-stream --with-http_ssl_module && make && make install
cat > /usr/local/nginx/conf/nginx.conf <<EOF
user nginx;
worker_processes auto;
worker_rlimit_nofile 655350;
error_log logs/error.log notice;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 655350;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"upstream_response_time" "$upstream_response_time"'
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 8 16k;
client_max_body_size 100M;
client_body_buffer_size 128k;
sendfile on;
tcp_nopush on;
keepalive_timeout 300;
keepalive_requests 8192;
server_tokens off;
underscores_in_headers on;
ignore_invalid_headers off;
proxy_intercept_errors on;
#proxy_http_version 1.1;
#proxy_set_header Connection "";
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "msie6";
server {
listen 80 default;
return 500;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/nginx/html;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
include /usr/local/nginx/conf/vhost/*.conf;
}
EOF
mkdir /usr/local/nginx/conf/vhosts
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload && systemctl start nginx && systemctl enable nginx