#安装gcc环境 yum install -y gcc-c++ #安装PCRE库,用于解析正则表达式 yum install -y pcre pcre-devel #zlib压缩和解压缩依赖 yum install -y zlib zlib-devel #SSL 安全的加密的套接字协议层,用于HTTPS yum install -y openssl openssl-devel下载并解压缩
下载地址:http://nginx.org/en/download.html
#用命令下载 wget -c https://nginx.org/download/nginx-1.20.2.tar.gz #解压缩 tar -zxf nginx-1.20.2.tar.gz新增账号
#新增账号 useradd -s /sbin/nologin nginx创建临时目录
#创建临时目录 mkdir -p /var/tmp/nginx修改代码
#修改代码,去掉Header中的Server信息 #解压后的nginx目录 vim src/http/ngx_http_header_filter_module.c #第49行至第51行修改前: static u_char ngx_http_server_string[] = "Server: nginx" CRLF; static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF; #第49行至第51行修改后: static u_char ngx_http_server_string[] = "" CRLF; static u_char ngx_http_server_full_string[] = "" NGINX_VER CRLF; static u_char ngx_http_server_build_string[] = "" NGINX_VER_BUILD CRLF;配置
#使用默认配置 ./configure #使用自定义配置 ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/run/nginx.pid --lock-path=/run/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/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --user=nginx --group=nginx --with-http_ssl_module --with-pcre编译和安装
#编译 make #安装 make install创建系统服务
#创建文件 vim /usr/lib/systemd/system/nginx.service #内容如下 [Unit] Description=The nginx HTTP and reverse proxy server After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process #不拿掉会开不起来 #PrivateTmp=true [Install] WantedBy=multi-user.target启动停止
#启动 systemctl start nginx #停止 systemctl stop nginx #重启 systemctl restart nginx



