linux下安装nginx
-
确保nginx的依赖项都安装
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel
-
下载nginx包(nginx-1.14.2.tar.gz),使用winSCP上传到/software目录下
-
解压nginx包到当前目录
[root@localhost software]# tar -zxvf nginx-1.14.2.tar.gz
-
进入nginx目录
[root@localhost software]# cd /software/nginx-1.14.2
-
检查配置
[root@localhost nginx-1.14.2]# ./configure
-
编译安装
[root@localhost nginx-1.14.2]# make & make install
编安装后会看到下面输出:
…
cp conf/nginx.conf ‘/usr/local/nginx/conf/nginx.conf.default’
test -d ‘/usr/local/nginx/logs’
|| mkdir -p ‘/usr/local/nginx/logs’
test -d ‘/usr/local/nginx/logs’
|| mkdir -p ‘/usr/local/nginx/logs’
test -d ‘/usr/local/nginx/html’
|| cp -R html ‘/usr/local/nginx’
test -d ‘/usr/local/nginx/logs’
|| mkdir -p ‘/usr/local/nginx/logs’
make[1]: 离开目录“/soft/nginx-1.14.2”
[1]+ 退出 2 make
-
转到目录/usr/local/nginx
[root@localhost software]# cd /usr/local/nginx
-
查看nginx版本
[root@localhost nginx]# ./sbin/nginx -v
nginx version: nginx/1.14.2
解释: 到这里,nginx已成功安装 -
直接启动nginx
[root@localhost nginx]# ./sbin/nginx
-
关闭linux防火墙
[root@192 nginx]# systemctl stop firewalld.service
-
浏览器访问 http://192.168.114.134/
-
查看nginx进程信息
[root@192 nginx]# ps aux|grep nginx
root 22594 0.0 0.0 20544 608 ? Ss 10:26 0:00 nginx: master process ./sbin/nginx
nobody 22595 0.0 0.1 20988 1572 ? S 10:26 0:00 nginx: worker process
root 22598 0.0 0.0 112724 984 pts/0 R+ 10:27 0:00 grep --color=auto nginx
说明:
可以看到nginx由一个主进程和一个工作进程组成 -
停止nginx
[root@192 nginx]# ./sbin/nginx -s stop
-
再查看nginx进程信息
root 22603 0.0 0.0 112724 988 pts/0 R+ 10:30 0:00 grep --color=auto nginx
说明:
可以看到没有nginx的进程信息了 -
nginx重启命令
[root@192 nginx]# ./sbin/nginx -s reload
-
nginx的工作进程配置
nginx.conf文件中
worker_processes 2;
将这个地方改为2,然后重启nginx./sbin/nginx -s reload
,然后查看nginx进程信息ps aux |grep nginx
,显示如下:
root 22607 0.0 0.1 20544 1368 ? Ss 10:32 0:00 nginx: master process ./sbin/nginx
nobody 22649 0.0 0.1 20992 1348 ? S 10:37 0:00 nginx: worker process
nobody 22650 0.0 0.1 20992 1348 ? S 10:37 0:00 nginx: worker process
root 22652 0.0 0.0 112724 984 pts/0 R+ 10:37 0:00 grep --color=auto nginx
-
运行nginx的用户
nginx.conf文件中
user root;
将这个地方改为root,然后重启nginx./sbin/nginx -s reload
,然后查看nginx进程信息ps aux |grep nginx
,显示如下:
root 22607 0.0 0.1 20544 1368 ? Ss 10:32 0:00 nginx: master process ./sbin/nginx
root 22654 0.0 0.1 20976 1428 ? S 10:41 0:00 nginx: worker process
root 22655 0.0 0.1 20976 1428 ? S 10:41 0:00 nginx: worker process
root 22657 0.0 0.0 112724 988 pts/0 R+ 10:41 0:00 grep --color=auto nginx