-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nginx.sh
262 lines (197 loc) · 6.8 KB
/
Nginx.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# Установка Nginx
apt update && \
apt install -y wget curl gpg && \
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null && \
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/mainline/debian bullseye nginx" | tee /etc/apt/sources.list.d/nginx.list && \
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | tee /etc/apt/preferences.d/99nginx && \
wget http://ftp.ru.debian.org/debian/pool/main/o/openssl/libssl1.1_1.1.1n-0+deb11u3_amd64.deb && \
dpkg -i libssl1.1_1.1.1n-0+deb11u3_amd64.deb && \
rm libssl1.1_1.1.1n-0+deb11u3_amd64.deb && \
apt update && \
apt install -y nginx && \
sed -i 32i\ 'include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf && \
systemctl restart nginx
########## Создание сайта Nginx c доменным именем your-domain.com
sudo mkdir -m 777 -p /var/www/your-domain.com
nano /etc/nginx/sites-available/your-domain.com
server {
listen 80;
server_name your-domain.com;
return 301 https://www.your-domain.com$request_uri;
}
server {
listen 80;
server_name www.your-domain.com;
root /var/www/your-domain.com;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
server {
listen 443 ssl http2;
server_name www.your-domain.com;
root /var/www/your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
########## Скопировать файлы сайта в директорию /var/www/your-domain.com
########## Настройка https переадресаций на доменное имя + прокси на https с tls сертификатом
nano /etc/nginx/sites-available/proxy
# Grafana primary listener and redirect
server {
listen 80;
server_name grafana.your-domain.com;
return 301 https://$host$request_uri;
}
# Grafana ssl config
server {
listen 443 ssl http2;
server_name grafana.your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Http-Version $server_protocol;
}
}
####################################################################
# Influxdb primary listener and redirect
server {
listen 80;
server_name influxdb.your-domain.com;
return 301 https://$host$request_uri;
}
# Influxdb ssl config
server {
listen 443 ssl http2;
server_name influxdb.your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
location / {
proxy_pass http://127.0.0.1:8086;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Http-Version $server_protocol;
}
}
####################################################################
# Nodered primary listener and redirect
server {
listen 80;
server_name nodered.your-domain.com;
return 301 https://$host$request_uri;
}
# Nodered ssl config
server {
listen 443 ssl http2;
server_name nodered.your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
location / {
proxy_pass http://127.0.0.1:1880;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Http-Version $server_protocol;
}
}
####################################################################
# Chirpstack primary listener and redirect
server {
listen 80;
server_name chirpstack.your-domain.com;
return 301 https://$host$request_uri;
}
# Chirpstack ssl config
server {
listen 443 ssl http2;
server_name chirpstack.your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Http-Version $server_protocol;
}
}
####################################################################
# Chirpstack-api primary listener and redirect
server {
listen 80;
server_name chirpstack-api.your-domain.com;
return 301 https://$host$request_uri;
}
# Chirpstack-api ssl config
server {
listen 443 ssl http2;
server_name chirpstack-api.your-domain.com;
ssl_certificate /etc/nginx/sites-available/cert.crt;
ssl_certificate_key /etc/nginx/sites-available/key.pem;
location / {
proxy_pass http://127.0.0.1:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Http-Version $server_protocol;
}
}
#Правки в основнмо конфиг файле nginx, итоговый должен быть таким:
nano /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
worker_cpu_affinity auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
sendfile on;
keepalive_timeout 65;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_buffers 64 8k;
gzip_comp_level 5;
gzip_min_length 512;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
gzip_proxied any;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_read_timeout 120s;
map $scheme $fastcgi_https {
default off;
https on;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
sudo ln -s /etc/nginx/sites-available/your-domain.com /etc/nginx/sites-enabled/ && \
sudo ln -s /etc/nginx/sites-available/proxy /etc/nginx/sites-enabled/proxy
sudo nginx -t && \
sudo service nginx reload && \
sudo systemctl restart nginx