1.安装部署nginx
(1)安装
tar zxf nginx-1.14.0.tar.gz
vim auto/cc/gcc
#CFLAGS="$CFLAGS -g"
##注销日志的debug模式,否则安装会产生多余的垃圾文件(占内存)
vim src/core/nginx.h
#define NGINX_VER "nginx/"
##删除版本,其他主机访问的时候看不到版本
yum install -y gcc pcre-devel openssl-devel
./configure --prefix=/usr/local/nginx --with-file-aio
make && make install
(2)开启:nginx
/usr/local/nginx/sbin/nginx //直接开启
ln -s /usr/local/nginx/sbin/nginx /sbin/ //做软链接,然后直接开启
nginx //直接开启
(3)nginx默认属于nobody用户,可以新建nginx用户,使其属于nginx用户(也可以不设置)
ps -aux | grep nginx //查看nginx属于那个用户
//nobody用户
##生成nginx用户,管理nginx
useradd -s /sbin/nologin
编辑主配置文件:
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx;
worker_processes 2;
nginx -s reload //重启
ps -aux | grep nginx //再次查看,属于nginx用户
//nginx
注:
nginx -t | 配置文件语法检测 |
---|---|
nginx -s stop | 关闭 |
nginx -s reload | 重启 |
nginx -v | 查看版本信息 |
nginx -V | 查看版本信息以及编译信息(加入了那些模块) |
(3) 语法检测设置:编写配置文件会显示颜色
mkdir ~/.vim
cp -r /root/nginx-1.17.1/contrib/vim/* ~/.vim
(4) 除了做软链接,还可以做systemd方式管理
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/nginx.service
vim /etc/systemd/system/nginx.service
## 修改配置文件内容如下:
[Unit]
Description