Nginx 介绍 Nginx是一种流行的开源Web服务器和反向代理服务器。 它的官方网站是nginx.org,而nginx.com是Nginx软件的商业版本的网站。 nginx.org是Nginx的官方网站,提供了所有版本的Nginx软件的下载,包括稳定版、主线版和开发版。 我们平时还是会使用开源版本,以下为开源版本编译介绍 安装准备 1 官网下载源码 一般我们会使用Stable version版本的代码 命令:wget https://nginx.org/download/nginx-1.26.0.tar.gz 2 编译库安装 GCC编译器 : gcc gcc-c++ 正则表达式PCRE库 : pcre pcre-devel zlib压缩库 : zlib zlib-devel OpenSSL开发库 : openssl openssl-devel 命令:yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 如果系统为8以上,也可以使用dnf install -y 开始编译 # 创建nginx用户与用户组 groupaddd nginx useradd -g nginx nginx #解压nginx源码包并进入nginx源码根目录 [root@localhost ~]# tar -axv -f nginx-1.26.0.tar.gz && cd nginx-1.26.0 # 1 生成makefile文件 ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --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-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module # 2 编译和安装 make && make install # 3 安装成功执行以下命令查看nginx版本号 [root@localhost nginx]# nginx -v nginx version: nginx/1.26.0 nginx -V 可以看到除了版本之外其他安装模块信息 如果想在Nginx中使用brotli压缩,可如下操作 # 安装brotli dnf install -y brotli brotli-devel 或 yum install -y brotli brotli-devel # 在编译时,添加brotli模块 ./configure \ --prefix=/etc/nginx \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ --user=nginx \ --group=nginx \ --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-stream \ --with-stream_realip_module \ --with-stream_ssl_module \ --with-stream_ssl_preread_module \ --add-module=/opt/soft/install/ngx_brotli 添加服务并设置开机启动 1、服务配置 [root@localhost]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target ​ [Service] Type=forking PIDFile=/etc/nginx/logs/nginx.pid ExecStartPre=/etc/nginx/sbin/nginx -t -c /etc/nginx/conf/nginx.conf ExecStart=/etc/nginx/sbin/nginx -c /etc/nginx/conf/nginx.conf ExecReload= /etc/nginx/sbin/nginx -s reload ExecStop= /etc/nginx/sbin/nginx -s stop PrivateTmp=true ​ [Install] WantedBy=multi-user.target 2、设置执行权限 [root@localhost]# chmod +x /usr/lib/systemd/system/nginx.service 3、服务使用说明 [root@localhost.com sbin]## systemctl daemon-reload # 重新加载服务 [root@localhost.com sbin]# systemctl start nginx.service # 启动 [root@localhost.com sbin]#systemctl stop nginx.service # 停止 [root@localhost.com sbin]# systemctl reload nginx.service # 修改配置后重新加载生效 [root@localhost.com sbin]# systemctl restart nginx.service # 重启 [root@localhost.com sbin]# systemctl status nginx # 查看服务状态 4、设置开机启动 [root@localhost]# systemctl enable nginx.service
Read More ~