一、linux下安装
(1)先安装pcre,用于nginx的Rewrite 功能
下载pcre
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
解压缩
tar -zxvf pcre-8.35.tar.gz
编译安装
cd pcre-8.35
./configure # 若权限不够,使用sudo
make && make install
验证
pcre-config --version
(2)安装nginx
下载
wget http://nginx.org/download/nginx-1.22.1.tar.gz
解压缩、编译安装
tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1
./configure
make && make install
验证
whereis nginx # /usr/local/nginx
/usr/local/nginx/sbin/nginx -v # nginx version: nginx/1.22.1
二、Nginx常用命令
cd /usr/local/nginx/sbin/
./nginx # 启动
./nginx -s stop # 快速停止
./nginx -s quit # 安全停止
./nginx -s reload # 重新加载配置文件
./nginx -t # 验证config文件是否正确
ps aux|grep nginx # 查看进程名包含“nginx”的进程
netstat -tunlp|grep 80 # 查看80端口占用情况
三、常见问题
1、启动Nginx报错
error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory