祈祷中...

这里安装的是1.25.1

下载源码

下载

1
wget http://nginx.org/download/nginx-1.25.1.tar.gz

解压

1
tar zxvf nginx-1.25.1.tar.gz

安装编译环境

1
2
yum update
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

进入nginx源码目录

1
cd nginx-1.25.1

编译和安装

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
./configure \
--prefix=/usr/local\nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module

编译安装

1
make && make install

验证

1
/usr/local/nginx/sbin/nginx -v

输出如下

1
nginx version: nginx/1.25.1

创建软连接

1
ln -s /usr/local/nginx /usr/bin/nginx

开机自启

1
systemctl enable nginx.server

nginx配置文件

打开配置文件

1
vim /usr/local/nginx/nginx.conf

开启gzip压缩
在http 里添加

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
gzip  on;
gzip_comp_level 5;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_proxied any;
gzip_vary on;
gzip_types
application/javascript
application/x-javascript
text/javascript
text/css
text/xml
application/xhtml+xml
application/xml
application/atom+xml
application/rdf+xml
application/rss+xml
application/geo+json
application/json
application/ld+json
application/manifest+json
application/x-web-app-manifest+json
image/svg+xml
text/x-cross-domain-policy;
gzip_static on;
gzip_disable "MSIE [1-6]\.";

网站使用http2 http3

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
server {
listen 80; #监听80端口
listen 443 default quic reuseport; #开启http3 quic
listen 443 default ssl; 开启ssl

http2 on; #开启http2支持

server_name fantasy.kim www.fantasy.kim; #监听地址

ssl_certificate /home/ssl/fantasy.crt; #ssl签名证书
ssl_certificate_key /home/ssl/fantasy.key; #ssl签名密钥

ssl_session_cache shared:SSL:10M; #ssl缓存大小
ssl_session_timeout 10M;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_buffer_size 4k;
ssl_ciphers 'ECDHE+AESGCM:DHE+AESGCM:HIGH:!aNULL:!MD5;';
ssl_prefer_server_ciphers on;

access_log /home/hexo/logs/access.log main; #log 文件地址
error_log /home/hexo/logs/error.log error; #error log 文件地址

location / {
if ($http_x_forwarded_proto != "https") {
rewrite ^/(.*)$ https://fantasy.kim/$1 permanent;
} #http重定向到https
gzip_static on; #使用gzip推送
root /home/hexo/public; #项目根目录
index index.html;
error_page 404 404.html;
}
}

检查配置文件有没有问题

1
nginx -t

开启nginx

1
nginx