这里安装的是1.25.1
下载源码
下载
wget http://nginx.org/download/nginx-1.25.1.tar.gz
解压
tar zxvf nginx-1.25.1.tar.gz
安装编译环境
yum update
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
进入nginx源码目录
cd nginx-1.25.1
编译和安装
配置
./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
编译安装
make && make install
验证
/usr/local/nginx/sbin/nginx -v
输出如下
nginx version: nginx/1.25.1
创建软连接
ln -s /usr/local/nginx /usr/bin/nginx
开机自启
systemctl enable nginx.server
nginx配置文件
打开配置文件
vim /usr/local/nginx/nginx.conf
开启gzip压缩 在http 里添加
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
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;
}
}
检查配置文件有没有问题
nginx -t
开启nginx
nginx
说些什么吧!