说明
- 使用的操作系统是CentOs7/Ubuntu20
下载安装
-
安装依赖(也可以根据./configure时的报错信息来选择性安装)
# 其中openssl和openssl-devel是用于nginx开启https的 # centos安装依赖 yum install pcre pcre-devel gcc gcc-c++ ncurses-devel perl zlib gzip zlib-devel openssl openssl-devel # ubuntu20 安装依赖 sudo apt install build-essential libpcre3-dev zlib1g-dev libssl-dev libxml2-dev libxslt1-dev libgd-dev libgeoip-dev libperl-dev
-
跳转到安装目录
cd /server/
-
下载
wget http://nginx.org/download/nginx-1.16.0.tar.gz
-
解压
tar -xvzf nginx-1.16.0.tar.gz
-
进入主目录
cd nginx-1.16.0
-
编译
# 该命令会安装https相关组件 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
-
安装
make & make install
-
查看安装结果(并不是安装在了当前目录下,可以通过whereis 查看安装目录)
whereis nginx # 一般安装在/usr/local/nginx目录下 cd /usr/local/nginx
-
将nginx放入系统变量
vi /etc/profile # 添加下面几句 export NGINX_HOME=/usr/local/nginx export PATH=$NGINX_HOME/sbin:$PATH
-
刷新环境变量
source /etc/profile
常用命令
- 启动
nginx - 停止
nginx -s stop - 重启
nginx -s reload - 检查 nginx.conf配置文件
nginx -t
验证启动成功与否
- 浏览器访问
http://ip地址
即可,注意http默认端口就是80