一、编译前提,需要安装必要的包
yum install gcc pcre-devel openssl-devel zlib-devel wget -y
(wget不是编译必须的,只是我后面要下载东西用,就一起安装)
二、下载对应的NGINX包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
三、创建nginx用户
useradd -r -s /sbin/nologin nginx
四、解压nginx到/data/下
tar xvf nginx-1.16.1.tar.gz -C /data/
(路径自定义)
五、进入解压的nginx目录中
cd /data/nginx-1.16.1/
六、编译安装
./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
计划安装的路径在/apps/
七、开始编译
make -j 2 && make install
-j 2 表示CPU两核,可以按照实际CPU核数定义,越多越快
八、为了方便启动可以创建软链接或者修改PATH变量
ln -s /apps/nginx/sbin/nginx /usr/sbin/
九、测试访问
[18:50:22 root@localhost ~]#curl 192.168.1.4 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
十、设置为开机自启动
1、修改centos7自带的开机自启动文件中
vim /etc/rc.d/rc.local
2、添加NGINX的路径
/usr/sbin/nginx
3、这个文件默认没有执行权限,添加执行权限
chmod +x /etc/rc.d/rc.local
原文:https://www.cnblogs.com/alexlv/p/14819045.html