1.源码编译安装:
[root@17dns ~]# wget https://nginx.org/download/nginx-1.27.0.tar.gz
2.解压:
[root@17dns ~]# tar -zxvf nginx-1.27.0.tar.gz
3.安装gcc等工具
[root@17dns ~]# yum -y install gcc gcc-c++
[root@17dns ~]# yum -y install make lrzsz openssl-devel pcre-devel
4.编译,配置文件
[root@17dns ~]# cd nginx-1.27.0/
[root@17dns nginx-1.27.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-stream[root@17dns nginx-1.27.0]# make && make install
[root@17dns nginx-1.27.0]# useradd -s /bin/nologin -M nginx
5.检查目录:
[root@17dns nginx-1.27.0]# tree /usr/local/nginx/
5.查看文件:
[root@17dns nginx-1.27.0]# cd /usr/local/nginx/
[root@17dns nginx]# ls
conf html logs sbin
6.启服务
[root@17dns nginx]# ./sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@17dns nginx]#
6.主配置文件:
[root@17dns nginx]# vim /usr/local/nginx/conf/nginx.conf
7.nginx服务控制:
[root@17dns nginx]# nginx
-bash: nginx: 未找到命令
[root@17dns nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/
[root@17dns nginx]# ls -l /usr/bin/nginx
lrwxrwxrwx. 1 root root 27 7月 29 16:15 /usr/bin/nginx -> /usr/local/nginx/sbin/nginx
[root@17dns nginx]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@17dns nginx]#
8. 用systemctl 启用nginx
[root@17dns nginx]# vim /usr/lib/systemd/system/nginx.service
[root@17dns nginx]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=Flase[Install]
WantedBy=multi-user.target
[root@17dns nginx]# systemctl daemon-reload
[root@17dns nginx]# reboot
只能重启后使用
9.添加监控块:
[root@17dns ~]# vim /usr/local/nginx/conf/nginx.conf
在47行加:
location /status{
stub_status on;
access_log off;
}[root@17dns ~]# systemctl restart nginx.service
监听测试,主机在访问一次192.168.2.17