编译安装 Nginx

一、下载

https://nginx.org/en/download.html

(三方带插件版)https://openresty.org/cn/download.html

(淘宝基于 Nginx 的修改版)https://tengine.taobao.org/

yum install -y wget
wget http://nginx.org/download/nginx-1.16.1.tar.gz -O /opt/nginx-1.16.1.tar.gz

二、编译

tar -zxf nginx-1.16.1.tar.gz -C /opt/
# 安装编译环境
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel
# 设置安装路径
cd /opt/nginx-1.16.1
./configure --prefix=/opt/nginx
# 编译安装
make && make install

设置安装路径完成

编译安装完成

三、常用命令(https://nginx.org/en/docs/switches.html

在线生成配置文件:https://nginxconfig.io/

./nginx # 启动 nginx
nginx -s reload | reopen | stop | quit  # 重新加载配置 | 重启 | 停止 | 退出 nginx
nginx -t   # 测试配置是否有语法错误

nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]

-?,-h           : 打开帮助信息
-v              : 显示版本信息并退出
-V              : 显示版本和配置选项信息,然后退出
-t              : 检测配置文件是否有语法错误,然后退出
-q              : 在检测配置文件期间屏蔽非错误信息
-s signal       : 给一个 nginx 主进程发送信号:stop(停止), quit(退出), reopen(重启), reload(重新加载配置文件)
-p prefix       : 设置前缀路径(默认是:/usr/local/nginx/)
-c filename     : 设置配置文件(默认是:/usr/local/nginx/conf/nginx.conf)
-g directives   : 设置配置文件外的全局指令

windows 下重启 nginx(restart.cmd)

taskkill /f /im nginx.exe
nginx.exe

https://nginx.org/en/docs/configure.html

原文地址:https://www.cnblogs.com/jhxxb/p/11525624.html