# 首先安装需要使用的扩展工具包yum源
yum -y install epel-release yum install net-tools wget nscd lsof
# dns缓存启动dns服务,提高域名解析响应速度
systemctl start nscd.service systemctl enable nscd.service
# 修改文件打开数限制:单进程默认打开文件数为1024 实现高并发可以调整数值为 65536
echo "* soft nofile 65536 * hard nofile 65536 " >> /etc/security/limits.conf
# 创建存放目录
mkdir -p /opt/data/source cd /opt/data/source
# 下载Nginx
wget https://nginx.org/download/nginx-1.17.4.tar.gz
# 解压Nginx
tar zxvf nginx-1.17.4.tar.gz
# 安装编译工具及依赖库
yum -y install pcre-devel zlib-devel openssl-devel libxm12-devel libxslt-devel gd-devel GeoIP-devel jemalloc-devel libatomic_ops-devel perl-devel perl-ExtUtils-Embed
# 编译参数
./configure
提示:默认安装在/usr/local/nginx下
# 添加第三方静态模块
./configure --add-module=../nginx_http_proxy_connect_module
# 添加第三方动态模块
./configure --add-dynamic-module=../ngx_http_proxy_connect_module --with-compat
# 编译及安装
make && make install
# 关闭防火墙
systemctl stop firewalld
# 启动nginx
cd /usr/local/nginx/sbin ./nginx
# 查看nginx 是否启动
ps -ef|grep nginx
# 查看端口占用
tlnp,分别表示查看tcp协议,查看监听服务,不解析名称,显示进程名和pid
# 将Nginx添加到环境变量
cat >/etc/profile.d/nginx.sh<<EOF PATH=$PATH:/usr/local/nginx/sbin EOF
source /etc/profile
ln -s /usr/local/nginx/conf /etc/nginx
基本使用命令:
nginx 启动nginx
nginx -t 执行配置文件检测
nginx -t -q 执行配置文件检测 只输出错误信息
nginx -s stop
nginx -s quit
nginx -s reopen
nginx -s reload
nginx -p /usr/local/newnginx 指定nginx的执行目录
nginx -c /etc/nginx/nginx.conf 指定nginx的执行目录
nginx -m 列出所有的编译模块
nginx -l 列出支持的所有指令
# 将nginx注册成系统服务
cat >/usr/lib/systemd/system/nginx.service <<EOF [Unit] Description=nginx - web server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -t -q ExecReload=/usr/local/nginx/sbin/nginx -s reload -g "pid /usr/local/nginx/logs/nginx.pid;" ExecStop=/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target EOF
systemctl enable nginx systemctl start nginx systemctl reload nginx systemctl stop nginx systemctl status nginx
关于$MAINPID变量的说明:
https://blog.csdn.net/michaelwoshi/article/details/104078664