centos7 下安装 nginx-1.12.2

7 篇文章 0 订阅

1.环境:
centos7
nginx: nginx-1.12.2.tar.gz

2.下载nginx:

wget http://nginx.org/download/nginx-1.12.2.tar.gz

3.解压安装包

tar zxvf nginx-1.12.2.tar.gz

4.配置安装路径,cd nginx-1.12.2下

 ./configure --prefix=/usr/local/nginx

提示缺少包,要安装pcre ,pcre-devel,zlib,zlib-devel,那依次安装

yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel

5. 编译

make & make install

6.启动Nginx,切换到/usr/local/nginx 下

看到如下4个目录
./
….conf 配置文件
… html 网页文件
…logs 日志文件
…sbin 主要二进制程序

./sbin/nginx

7. 查看启动的进程和端口

[root@localhost nginx]# ps -ef|grep nginx
root      16050      1  0 00:44 ?        00:00:00 nginx: master process ./sbin/nginx
nobody    16051  16050  0 00:44 ?        00:00:00 nginx: worker process
root      16063   6097  0 00:44 pts/1    00:00:00 grep --color=auto nginx
[root@localhost nginx]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1352/redis-server 1 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16050/nginx: master 
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2479/dnsmasq        
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1142/sshd           
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1148/cupsd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2321/master         
tcp6       0      0 :::22                   :::*                    LISTEN      1142/sshd           
tcp6       0      0 ::1:631                 :::*                    LISTEN      1148/cupsd          
tcp6       0      0 :::8888                 :::*                    LISTEN      2648/java           
tcp6       0      0 ::1:25                  :::*                    LISTEN      2321/master       

8.如有进程点用了80端口,可以杀掉占用的进程

netstat -ant 
kill -9 pid

9.信号控制 停止或启动nginx

[root@localhost nginx]# ps aux|grep nginx
root      16050  0.0  0.0  20484   612 ?        Ss   00:44   0:00 nginx: master process ./sbin/nginx
nobody    16051  0.0  0.1  23012  1380 ?        S    00:44   0:00 nginx: worker process
root      17288  0.0  0.0 112648   948 pts/1    S+   01:04   0:00 grep --color=auto nginx
[root@localhost nginx]# kill -INT 16050
[root@localhost nginx]# ps aux|grep nginx
root      17477  0.0  0.0 112648   948 pts/1    S+   01:07   0:00 grep --color=auto nginx
[root@localhost nginx]# ./sbin/nginx 
[root@localhost nginx]# ps aux|grep nginx
root      17495  0.0  0.0  20484   616 ?        Ss   01:08   0:00 nginx: master process ./sbin/nginx
nobody    17496  0.0  0.1  23012  1384 ?        S    01:08   0:00 nginx: worker process
root      17500  0.0  0.0 112648   948 pts/1    S+   01:08   0:00 grep --color=auto nginx
vim ./conf/nginx.conf

这里写图片描述

这里写图片描述

访问nginx首页

curl http://localhost 

也可以在浏览中输入 http://ip_address 进行访问

10.HUP 优雅的重启读取配置文件

kill -HUP 16050  ( nginx master pid)
  1. 也可以用其他的命令
[root@localhost nginx]# ./sbin/nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
./sbin/nginx -s reload  相当于 kill -HUP 'cat ./logs/nginx.pid'
./sbin/nginx -s stop  
./sbin/nginx -s quit 
./sbin/nginx -s reopen 相当于 kill -USR1 'cat ./logs/nginx.pid'

11.测试配置文件是配置正确

[root@localhost 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
[root@localhost nginx]# 
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值