**编译安装nginx **
1,首先需要安装编译需要的依赖。打开终端并运行以下命令来安装这些依赖:
yum install -y gcc gcc-c++ make kernel-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel
gcc-c++和make是编译工具。zlib-devel、pcre-devel和openssl-devel是 Nginx 处理 HTTP 请求所需的库的开发包kernel-devel、openssl-devel是内核软件包和加密库
2,下载nginx安装包
wget https://nginx.org/download/nginx-1.26.0.tar.gz
tar -zxvf nginx-1.26.0.tar.gz
cd nginx-1.26.0
3,编译安装nginx
./configure \
--prefix=/usr/local/nginx \
--user=root \
--group=root \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/log/error.log \
--http-log-path=/usr/local/nginx/log/access.log \
--pid-path=/usr/local/nginx/sbin/nginx.pid \
--lock-path=/usr/local/nginx/sbin/nginx.lock \
--http-client-body-temp-path=/usr/local/nginx/client_temp \
--http-proxy-temp-path=/usr/local/nginx/proxy_temp \
--http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp \
--http-scgi-temp-path=/usr/local/nginx/scgi_temp \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
make
make install
4,修改配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root /usr/local/nginx/download; #修改为自己的目录,ip + port 可直接下载当前目录的所有文件
autoindex on; #开启索引功能
autoindex_exact_size off; #关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
autoindex_localtime on; #显示本机时间而非 GMT 时间
}
}
}
#创建下载目录
mkdir -p /usr/local/nginx/download
#检查配置文件正确性
/usr/local/nginx/sbin/nginx -t
#启动nginx
/usr/local/nginx/sbin/nginx
##检查nginx是否启动
ss -ntlp |grep nginx
nginx编译安装,配置downloadUrl完成 打开浏览器,输入IP+Port 可看到可以下载的文件
至此大功告成