linux服务基础之编译安装nginx

时间:2022-12-29 07:46:51

nginx源码下载地址:

http://nginx.org/download/nginx-1.16.0.tar.gz  //根据需要下载其他版本

1. 下载nginx

# wget http://nginx.org/download/nginx-1.16.0.tar.gz

2. 安装nginx

解决依赖关系:

# yum install pcre-devel

添加运行nginx的用户和组:

# groupadd -r nginx
# useradd -r -g nginx nginx

编译安装nginx:

# tar xf nginx-1.16.0.tar.gz
# cd nginx-1.16.0
# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
# make && make install

创建nginx编译安装时需要的目录:

# mkdir -pv /var/tmp/nginx/{client,proxy,fastcgi,uwsgi}

测试:

# /usr/local/nginx/sbin/nginx  //运行nginx
# ss -tnlp  //查看80端口是否被监听
# ps aux | grep nginx
root 37932 0.0 0.1 46896 1108 ? Ss 18:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 37933 0.0 0.1 47336 1704 ? S 18:49 0:00 nginx: worker process
# elinks http://192.168.1.103  //可以看到nginx的欢迎页面