# 方式1:一键安装 wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz && tar -xvf lnmp1.9.tar.gz && cd lnmp1.9 && ./install.sh nginx ./upgrade.sh nginx # 升级 # help https://lnmp.org/install.html # 方式2:手工编译 # 环境 yum -y install gcc gcc-c++ autoconf automake libtool make cmake yum -y install zlib zlib-devel openssl openssl-devel pcre-devel # 安装 pcre,配置、编译、安装 wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz tar -zxvf pcre-8.40.tar.gz cd pcre-8.40 ./configure make -j && make install -j # 创建 nginx 用户及组 groupadd nginx useradd -M -s /sbin/nologin -g nginx nginx # 下载 nginx http://nginx.org/en/download.html wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -zxvf nginx-1.20.1.tar.gz cd nginx-1.20.1 # [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 127 # 编辑安装包目录 vi auto/lib/openssl/conf # 搜索替换 /CORE_LIBS="$CORE_LIBS $NGX_LIBDL" CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include" CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a" CORE_LIBS="$CORE_LIBS $NGX_LIBDL" # 修改成以下代码(删除.openssl): CORE_INCS="$CORE_INCS $OPENSSL/include" CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a" CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a" CORE_LIBS="$CORE_LIBS $NGX_LIBDL" # 编译前配置,需要配置 ssl,即支持 https,再是启用 http2,需要安装对应的模块 # nginx 的 ssl 是基于 OpenSSL,而且 http2 对 OpenSSL 版本有要求,尽量最新 ./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 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-openssl=/usr/local/openssl # 编译、安装 make -j && make install -j # 启动 /usr/local/nginx/sbin/nginx # 停止 /usr/local/nginx/sbin/nginx -s stop # 重新载入 /usr/local/nginx/sbin/nginx -s reload # 查看版本 /usr/local/nginx/sbin/nginx -v # 查看所有的信息 /usr/local/nginx/sbin/nginx -V # 测试配置文件是否正常 /usr/local/nginx/sbin/nginx -t # 强制关闭 pkill nginx # 查看nginx配置文件 cat /usr/local/nginx/conf/nginx.conf # nginx软链接 ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx # help https://blog.csdn.net/bjnihao/article/details/52370089 https://www.cnblogs.com/huanhang/p/7580843.html https://www.jb51.net/article/137373.htm https://www.cnblogs.com/chenwz/p/7622983.html https://blog.csdn.net/john_f_lau/article/details/24863071 https://yq.aliyun.com/articles/117130?t=t1 # 方式3:yum 安装,创建以下文件 vi /etc/yum.repos.d/nginx.repo # 输入以下内容 [nginx] name=nginx repo # 稳定版 baseurl=https://nginx.org/packages/centos/$releasever/$basearch/ # 主线版 #baseurl=https://nginx.org/packages/mainline/centos/8/$basearch/ gpgcheck=0 enabled=1 # 内容结束 # 查看 yum list | grep nginx # 开始安装 yum install nginx # help https://blog.csdn.net/u011019141/article/details/78670333