编译安装nginx:
yum -y install wget screen #for CentOS/Redhat
下载组件:
wget http://nginx.org/download/nginx-1.15.8.tar.gz
解压:tar zxvf nginx-1.15.8.tar.gz
cd nginx-1.15.8
./configure --prefix=/usr/local/nginx --group=www --user=www --with-stream
发现报错:没有安装gcc
安装gcc:yum install gcc
好,安装完gcc后,再执行./configure --prefix=/usr/local/nginx --group=www --user=www --with-stream
发现报上面错误。好,安装PCRE:yum install pcre-devel
好,继续执行./configure --prefix=/usr/local/nginx --group=www --user=www --with-stream
又报错了,安装zlib:yum install zlib zlib-devel
继续执行./configure --prefix=/usr/local/nginx --group=www --user=www --with-stream
安装:yum -y install openssl
继续执行./configure --prefix=/usr/local/nginx --group=www --user=www --with-stream
好了,make && make install
配置启动文件:
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/var/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
LimitNOFILE=1000000
LimitNPROC=1000000
LimitCORE=1000000
[Install]
WantedBy=multi-user.target
启动nginx:systemctl start nginx
报没有www用户,新建www用户组和www用户
groupadd www
useradd -g www www
在/usr/local/nginx 新建var目录,不然启动nginx报错,启动nginx时会自动新建文件nginx.pid到var目录
启动nginx:systemctl start nginx,成功
[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]#