我的环境是Centos 7.3
一、 nginx服务器编译安装
yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel
cd /usr/local/src
wget 'http://nginx.org/download/nginx-1.14.2.tar.gz' --------下载1.14.2版本
yum install lrzsz -y --------如果不下载可以用rz
[root@zabbix src]# ll
total 992
-rw-r--r--. 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
[root@zabbix nginx-1.14.2]# ./configure --prefix=/usr/local/nginx -----我把路径设置/usr/local/nginx
[root@zabbix nginx-1.14.2]# make && make install
----------好啦,到这里Nginx的编译安装就完成了
二、Nginx环境配置
[root@zabbix nginx-1.14.2]# vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin/
[root@zabbix nginx-1.14.2]# source /etc/profile
[root@zabbix nginx-1.14.2]# nginx -V ----查看版本
- 检查Nginx配置: nginx -t
- 启动Nginx:nginx
- 关闭Nginx:nginx -s stop
[root@zabbix nginx-1.14.2]#nginx -s reload ----nginx 刷新重启
[root@zabbix nginx-1.14.2]# netstat -anptu|grep nginx
[root@zabbix nginx-1.14.2]# ps -ef|grep nginx
[root@zabbix nginx-1.14.2]# tail -f /usr/local/nginx/logs/error.log 看日志
三、 测试浏览器访问输入地址OK
四、使用systemctl管理Nginx,
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx (如果mysql也可以这样改)
After=network.target (网络启动)
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx (更改路径)
[Install]
WantedBy=multi-user.target (开机启动)
[root@zabbix nginx-1.14.2]# systemctl start nginx.service (这样就可以启动了)
-----------哈哈哈 好啦,Nginx的编译安装就搞定了