安装版本
- 本次安装环境为 CentOS 7
- 安装nginx版本为 nginx-1.18.0
安装步骤
- 首先安装C语言编译器:
yum -y install gcc gcc-c++ kernel-devel
- 然后我们安装nginx依赖的软件包:
yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
- 然后下载nginx安装包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
- 然后解压到指定目录
tar -zxvf nginx-1.18.0.tar.gz -C /usr/local/src/
- 来到指定目录之后经行配置
# 来到指定目录 cd /usr/local/src/nginx-1.18.0/ # 配置nginx ./configure \ --prefix=/opt/server/nginx \ --conf-path=/opt/server/nginx/conf/nginx.conf \ --pid-path=/opt/server/nginx/conf/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/opt/server/nginx/logs/error.log \ --http-log-path=/opt/server/nginx/logs/access.log \ --with-http_stub_status_module --with-http_ssl_module # 或者采用默认配置 ./configure
- 执行安装,使用命令 make install 然后来到 /opt/server/nginx/sbin 目录下,其中有一个nginx文件
- 使用命令启动nginx服务器
./nginx -c conf/nginx.conf
- 访问nginx所在服务器的80端口,以下是我的url请自行更改成自己的,注意包装端口已经开启或者防火墙关闭
http://192.168.235.7:80
- 如果看到这个界面代表安装成功:
如果你和我一样怕麻烦,那么请直接复制下面这一段代码一条一条执行吧,能安装成功的
#!/bin/bash cd /usr/local/src/ yum -y install gcc gcc-c++ kernel-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz -C /usr/local/src/ cd /usr/local/src/nginx-1.18.0/ ./configure \ --prefix=/opt/server/nginx \ --conf-path=/opt/server/nginx/conf/nginx.conf \ --pid-path=/opt/server/nginx/conf/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/opt/server/nginx/logs/error.log \ --http-log-path=/opt/server/nginx/logs/access.log \ --with-http_stub_status_module --with-http_ssl_module make install cd ../ rm -rf ./nginx-1.18.0 ./nginx-1.18.0.tar.gz cd /opt/server/nginx/sbin ./nginx -c conf/nginx.conf
然后访问前请关闭防火墙,配置开机自启步骤可参考这篇文档