Linux Install Nginx
一、安装
https://nginx.org/en/download.html & https://mirrors.huaweicloud.com/nginx/
(三方带插件版)https://openresty.org/cn/download.html
(淘宝基于 Nginx 的修改版)https://tengine.taobao.org
1、编译安装
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
设置安装路径完成
编译安装完成
2、YUM 源安装 Nginx
https://nginx.org/en/linux_packages.html#RHEL-CentOS
sudo yum install yum-utils vim /etc/yum.repos.d/nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true sudo yum-config-manager --enable nginx-mainline sudo yum install nginx
二、常用命令(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
nginx.cmd
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
chcp 65001 MODE con: COLS=35 LINES=25 cls @ECHO OFF rem SET NGINX_PATH=C:\CodeLib\nginx-1.10.3\ SET NGINX_PATH=%~dp0 TITLE Nginx GOTO MENU :MENU CLS ECHO. ECHO. * * * Nginx * * * * * * * * ECHO. * ECHO. * 1 Start UP Nginx * ECHO. * ECHO. * 2 Stop Nginx * ECHO. * ECHO. * 3 Restart Nginx * ECHO. * ECHO. * 4 Exit * ECHO. * ECHO. * * * * * * * * * * * * * * ECHO. ECHO.please enter no: set /p ID= IF "%id%"=="1" GOTO cmd1 IF "%id%"=="2" GOTO cmd2 IF "%id%"=="3" GOTO cmd3 IF "%id%"=="4" EXIT PAUSE :cmd1 ECHO. ECHO.Start UP Nginx...... cd %NGINX_PATH% IF NOT EXIST nginx.exe ECHO nginx.exe not found IF EXIST nginx.exe start nginx.exe ECHO.OK PAUSE GOTO MENU :cmd2 ECHO. ECHO.Stop Nginx...... taskkill /F /IM nginx.exe > nul ECHO.OK PAUSE GOTO MENU :cmd3 ECHO. ECHO.Stop Nginx...... taskkill /F /IM nginx.exe > nul ECHO.OK GOTO cmd1