准备安装依赖:
yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel
等依赖安装完成后,下载nginx,可以从官网找到合适的版本:nginx
#需要提前安装wget yum install wget
wget -c http://nginx.org/download/nginx-1.16.1.tar.gz
解压:
# tar -zxvf nginx-1.16.1.tar.gz
# cd nginx-1.16.1
*** nginx-1.16.1]#
具体是想默认配置安装还是自定义配置,可自行斟酌。
1.默认
./configure
2 配置具体 用户和用户组
./configure \
--prefix=/usr/local/nginx \
--pid-path=/usr/local/nginx/run \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_image_filter_module \
--with-debug
3 不依赖用户组
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
进行安装:
# make && make install
然后就是安装成功了
nginx基本操作
启动nginx
$ /usr/local/nginx/sbin/nginx
停止nginx
$ /usr/local/nginx/sbin/nginx -s stop
$ /usr/local/nginx/sbin/nginx -s quit
重启nginx
$ /usr/local/nginx/sbin/nginx -s reload
查看nginx进程:
[root@****html]# netstat -tlunp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 17506/nginx: master
[root@**** html]# ps -ef | grep nginx
root 17506 1 0 14:28 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 17507 17506 0 14:28 ? 00:00:00 nginx: worker process
root 17522 10068 0 14:39 pts/0 00:00:00 grep --color=auto nginx
[root@**** html]#
如果在第一次启动的时候遇到 nginx: [emerg] getpwnam("nginx") failed这个错误,没有安装nginx用户导致的无法启动,需要添加nginx用户,按下面命令操作即可,然后再次启动即可
[root@**** sbin]# id nginx
id: nginx: no such user
[root@**** sbin]# useradd -s /sbin/nologin -M nginx
[root@**** sbin]# /usr/local/nginx/sbin/nginx