一、依赖包
1、SSL功能需要openssl库
# yum install -y openssl
2、gzip模块需要zlib库
# yum install -y zlib
3、rewrite模块需要pcre库
# yum install pcre
4、添加nginx用户
# useradd -s /sbin/nologin -M nginx
二、安装
1、下载
# wget http://nginx.org/download/nginx-1.18.0.tar.gz
2、安装
# tar -zxvf nginx-1.18.0.tar.gz
# cd nginx-1.18.0
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-file-aio --with-http_realip_module
# make
# make install
3、检测
# /usr/local/nginx/sbin/nginx -t
输出:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
4、服务管理
4.1 启动
# /usr/local/nginx/sbin/nginx
4.2 重启:
# /usr/local/nginx/sbin/nginx –s reload
4.3 停止:
# /usr/local/nginx/sbin/nginx –s stop
4.4 强制关闭
# pkill nginx
三、配置
1、指定Nginx服务的用户和用户组
worker_processes 1;
user nginx nginx;
2、服务器配置
server {
listen 80;
server_name localhost;
root html;
index index.html index.htm;
}
3、PHP配置
四、开机自启动
在rc.local增加启动代码:
# vi /etc/rc.d/rc.local
底部增加一行:
/usr/local/nginx/sbin/nginx
设置可执行权限:
# chmod755/etc/rc.local