安装依赖
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel
下载nginx稳定版
#进入/usr/local目录
cd /usr/local
#创建nginx文件夹
mkdir nginx
#进入/usr/local/nginx的目录
cd /usr/local/nginx
#解压下载好的压缩包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压--编译--安装
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
#配置vim,使其语法高亮
mkdir .vim #自己创建一个.vim目录
cp -r contrib/vim/* ~/.vim/
#查看编译参数
./configure --help | more
#编译
./configure --prefix=/usr/local/nginx
#安装:
make && make install
#去prefix指定的目录下
cd /usr/local/nginx/
ls -l
total 16
drwxr-xr-x 2 root root 4096 Jul 9 13:37 conf
drwxr-xr-x 2 root root 4096 Jul 9 13:37 html
drwxr-xr-x 2 root root 4096 Jul 9 13:37 logs
drwxr-xr-x 2 root root 4096 Jul 9 13:37 sbin
#nginx服务器的主程序
ls /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
开放linux对外访问的端口号80
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
如果Centos7默认安装了firewalld
则使用如下命令
firewall-cmd --add-port=端口号/tcp --zone=public --permanent 添加某端口号放行
开启后重启防火墙,使得开放端口生效
firewall-cmd --reload 或者 service firewalld restart
nginx服务的启动操作
1: 默认配置文件启动
cd /usr/local/nginx/sbin
./nginx
指定配置文件启动
./nginx -c /usr/local/nginx/conf/nginx.conf
2: 查看帮助信息
./ngxin =h #查看帮助信息
可以找安装时候的配置
./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx
3:-t 检查配置文件是否正确
./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
验证
http://阿里云公网ip/
js.png
nginx停服务
cd /usr/local/nginx/sbin
./nginx -s stop
网友评论