nginx基础

nginx安装(docker)

1
2
3
4
5
6
7
# 拉取镜像
docker pull nginx:[tag]
# run
$ docker run -d -p 443:443 -p 80:80 --name website --network website_net -v /www/www.sdadgz.cn/html/:/usr/share/nginx/html/ -v /www/www.sdadgz.cn/config/:/etc/nginx/ nginx
挂载数据卷
/usr/share/nginx/html/ # 默认html
/etc/nginx/ # 配置文件

配置文件

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
server {
# ssl证书配置
listen 443 ssl;
server_name sdadgz.cn;

# 证书路径
ssl_certificate /etc/nginx/ssl/sdadgz.cn_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/sdadgz.cn.key;

# 不懂,复制的
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;

# 默认页
location / {
# 非根用alias,不知道为什么,反正能跑就完事了
root /usr/share/nginx/html;
index index.html index.htm;
}

# 官方模块download
location /download {
alias /etc/nginx/download;
autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}
}

# http转https
server {
listen 80;
server_name sdadgz.cn;
return 301 https://$host$request_uri;
}

跨域

放location里

header里记得加上自定义请求头 ,全删了换成*吧

1
2
3
4
5
6
7
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

if ($request_method = 'OPTIONS') {
return 204;
}

重定向

那个逼东西自动重定向到当前url的/static/而不是/frp/static/妈的解决不了,索性/frp指向7500了

1
2
3
4
5
6
7
8
# 控制面板
location /frp {
return 301 http://$host:7500/;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Scheme $scheme;
}