官方网站下载地址:
https://nginx.org/en/download.html
https://www.cnblogs.com/jackyzm/p/9600738.html 安装教程
解压
依然是直接命令:
tar -zxvf nginx-1.12.0.tar.gzcd nginx-1.12.0
1.使用默认配置
cd nginx-1.16.1/
./configure
编译安装
make
make install
…
查找nignix路径
[root@instance-609xznso nginx-1.16.1]# whereis nginx
nginx: /usr/local/nginx
[root@instance-609xznso nginx-1.16.1]#
启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
============
[root@instance-609xznso nginx-1.16.1]# ^C
[root@instance-609xznso nginx-1.16.1]# cd /usr/local/nginx/sbin
[root@instance-609xznso sbin]# ls
nginx
[root@instance-609xznso 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@instance-609xznso nginx]# ls /usr/local/nginx/conf
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@instance-609xznso nginx]# cd conf
[root@instance-609xznso conf]# vi nginx.conf
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
启动成功后,在浏览器可以看到这样的页面:
开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local
#!/bin/bash
THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
It is highly advisable to create own systemd services or udev rules
to run scripts during boot instead of using this file.
In contrast to previous versions due to parallel execution during boot
this script will NOT be run after all other services.
Please note that you must run ‘chmod +x /etc/rc.d/rc.local’ to ensure
that this script will be executed during boot.
touch /var/lock/subsys/local
/usr/loacal/nginx/sbin/nginx
~
[root@instance-609xznso sbin]# chmod 755 /etc/rc.local
[root@instance-609xznso sbin]#