Nginx配置笔记

简单记录一下用过的配置

1.基础配置
1
2
3
4
5
6
7
8
server {
listen 80;
server_name fran6k.live;
location / { #location路径
root /var/www/hexo; # 站点目录
index index.html index.htm;
}
}
2.配置同一端口,二级子域名
1
2
3
4
5
6
7
8
server {
listen 80;
server_name test.fran6k.live; #改成子域名即可
location / { #location路径
root /var/www/hexo; # 站点目录
index index.html index.htm;
}
}
3.配置SSL 80端口转发443
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
listen 80;
server_name fran6k.live;
rewrite ^ https://$http_host$request_uri? permanent;
}
server {
listen 443;
ssl on;
server_name fran6k.live; # 填写绑定证书的域名
ssl on; #开启ssl
ssl_certificate /etc/nginx/cert/1_fran6k.live_bundle.crt; #自己的证书路径
ssl_certificate_key /etc/nginx/cert/2_fran6k.live.key; #自己的证书路径
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 按照这个协议配置
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/fran6k.live.access.log; #log地址

location / {
root /var/www/hexo; # 站点目录
index index.html index.htm;
}
}
4.反向代理
1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 80;
server_name api.fran6k.live; #通过api.fran6k.live访问fran6k.live:25565
location / {
#反向代理的地址
proxy_pass https://fran6k.live:25565; #后台接口地址
#配置参数(重要)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

5.图片服务器
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
#正则表达式,访问/home/auServerData/images/路径下的文件
location ~ (images/).+(gif|jpg|jpeg|png)$ {
expires 24h;
root /home/auServerData/;#指定图片存放路径
access_log /home/auServerData/log/images.log;#日志存放路径
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /home/auServerData/;#图片访问路径
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1;#默认80端口
}
}