通过yum安装
yum install epel-release -y(企业级的镜像源)
yum install nginx-y
启动、停止、重启
service nginx start
service nginx stop
service nginx reload
nginx的配置文件位置 /etc/nginx/nginx.conf
二、源码编译安装
yum install -y make libtool gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
wget -nc http://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz cd nginx-1.14.0
./configure --prefix=/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre
make
make install /apps/nginx/sbin/nginx -V nginx的配置文件位置
/apps/nginx/conf/nginx.conf
语法检测 /apps/nginx/sbin/nginx –t
启动nginx /apps/nginx/sbin/nginx
重启nginx /apps/nginx/sbin/nginx –s reload
启动nginx后,在浏览器输入服务器的ip地址,可以看到欢迎界面。(查看本机ip的命令ip addr)
常见问题
1、报错 nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 端口被占用,
查看被占端口命令 ss -nalp|grep 80
2、如果无法访问欢迎界面,如何排查?
三步走
查看是否有nginx进程 ps aux |grep nginx
查看是否有监听端口 ss -nalp|grep 80
查看本机是否连同端口 telnet ip 80