Nginx官网
基础模板
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
server {
listen 80;
listen 443 ssl http2;
listen [::]:80;
listen [::]:443 ssl http2;
root /var/www/html;
index index index.html index.htm;
server_name xxx.xxx;
ssl_certificate /root/xxx.xxx.crt;
ssl_certificate_key /root/xxx.xxx.key;
location / {
try_files $uri $uri/ =404;
}
}
|
反向代理
docker容器内反代推荐使用 nginx-proxy-manager
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
|
#内部反代
server {
listen 80;
server_name xxx.xxx.xxx;
location / {
#用于获取用户真实IP
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#将域名的请求发到8080的端口
proxy_pass http://127.0.0.1:8080;
}
}
#外部反代
server {
listen 80;
server_name www.example.com;
location / {
proxy_pass http://example.com:80;
}
}
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
location / {
proxy_pass https://example.com:443;
}
}
|
没有证书,就反代80端口
限制上传大小
1
2
3
4
5
|
client_max_body_size 10m;
# 设置到http{}内,控制全局nginx所有请求报文(附件)大小;
# 设置到server{}内,控制该server的所有请求报文(附件)大小;
# 设置到location{}内,只控制满足该路由规则的请求报文(附件)大小。
|
ssl优化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#ssl协议相关
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
#ssl缓存优化
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# 指定TLS协议版本 1.2和1.3
# 定义加密套件和算法
# 服务器加密套件优先级
# SSL会话缓存类型和大小
# SSL会话缓存储存时间
|