Centos7 安装nginx-1.16.1

准备安装依赖:

 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 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值