重装 Centos 7 系统后的环境初始化

修改主机名

1
2
# sudo hostnamectl set-hostname <new_hostname>
sudo hostnamectl set-hostname xxcc

安装nginx

1
2
3
4
5
6
7
yum install nginx -y # yum 安装 nginx
systemctl start nginx # 启动 nginx
systemctl status nginx # 查看 nginx 状态
systemctl enable nginx # 设置 nginx 开机自动开启

systemctl restart nginx # 重启 nginx
nginx -s reload # 重启nginx (一般用于修改配置后启用)

更详细配置见下方 nginx 配置

unzip

1
yum install unzip -y # yum 安装 nginx

nginx 配置

blog.conf

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
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name xxcc.fun;

return 301 https://xxcc.fun$request_uri;
}

# Settings for a TLS enabled server.
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name xxcc.fun;
root /var/www/blog;

access_log /var/log/nginx/access-blog.log;
error_log /var/log/nginx/error-blog.log warn;

ssl_certificate "/etc/nginx/ssl/xxcc.fun_bundle.crt";
ssl_certificate_key "/etc/nginx/ssl/xxcc.fun.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

location / {
index index.html index.htm;
autoindex off;
}

# assets
location /assets{
alias /var/www/assets;
autoindex off;
valid_referers *.xxcc.fun xxcc.fun;
if ($invalid_referer) {
return 403;
}
}

# sub features path
set $feat_path "/var/www/blog_sub_features";

location /background{
alias $feat_path/background;
index index.html;
}
location /watermark{
alias $feat_path/watermark-vue;
index index.html;
}
location /stars{
alias $feat_path/stars;
index index.html;
}

location /calculator{
alias $feat_path/calculator-keyboard;
index index.html;
}

location /painter{
alias $feat_path/websocket-painter/public;
index index.html;
}

location ^~ /painter/wss {
proxy_pass http://127.0.0.1:9001/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Remote_addr $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 600s;
}

location /nest-api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/nest-api;
}

location /pdf {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080/pdf;
}

include /etc/nginx/conf.d/game.config;

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

gzip on;
gzip_buffers 32 4K;
gzip_comp_level 5;
gzip_min_length 1k;
gzip_types application/javascript text/css text/xml;
gzip_vary on;

}

game.conf

1
2
3
4
5
6
7
8
9
10
11
set $game_path "/var/www/Game";

location /game/Evolve{
alias $game_path/Evolve;
index index.html;
}

location /game/traffic-run-game{
alias $game_path/traffic-run-game;
index index.html;
}