Nginx
一、下载编译软件和依赖包
[root@lnmp ~]# yum -y install make gcc gcc-c++ pcre-devel zlib-devel zlib openssl openssl-devel
创建nginx运行用户
[root@centos7-2 opt]# useradd -M -s /sbin/nologin www
下载nginx源码
[root@centos7-2 opt]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@centos7-2 opt]# tar -xvf nginx-1.18.0.tar.gz && cd nginx-1.18.0
二、编译
检测是否缺少什么依赖
[root@centos7-2 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx \
> --with-http_dav_module \
> --with-http_stub_status_module \
> --with-http_addition_module \
> --with-http_sub_module \
> --with-http_ssl_module \
> --user=www \
> --group=www
确认无报错信息即可开始安装
[root@centos7-2 nginx-1.18.0]# make && make install
三、修改nginx.conf配置文件
[root@centos7-2 nginx-1.18.0]# ln -s /usr/local/nginx/conf/nginx.conf /etc/
[root@centos7-2 nginx-1.18.0]# vim /etc/nginx.conf
php放前面,优先读取
四、配置环境变量
[root@centos7-2 nginx-1.18.0]# echo "PATH=/usr/local/nginx/sbin/:$PATH" >> /etc/profile
[root@centos7-2 nginx-1.18.0]# source /etc/profile
[root@centos7-2 nginx-1.18.0]# nginx
[root@centos7-2 nginx-1.18.0]# ps -ef | grep nginx
root 7572 1 0 05:59 ? 00:00:00 nginx: master process nginx
www 7573 7572 0 05:59 ? 00:00:00 nginx: worker process
root 7578 1056 0 05:59 pts/0 00:00:00 grep --color=auto nginx
[root@centos7-2 nginx-1.18.0]# netstat -tulnp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7572/nginx: master
五、配置nginx以守护进程方式启动
[root@centos7-2]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
EnvironmentFile=/usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@centos7-2]# systemctl daemon-reload
[root@centos7-2]# systemctl start nginx
[root@centos7-2]# systemctl status nginx
[root@centos7-2]# systemctl stop nginx
在浏览器输入本机ip,查看nginx是否安装成功