第一种方法:
1.安装前准备:
yum install yum-utils
yum-utils功能简介:管理repository及扩展包的工具 (主要是针对repository)
2.添加源
到 cd /etc/yum.repos.d/ 目录下
新建 vim nginx.repo 文件
输入以下信息
3.安装Nginx
通过yum search nginx看看是否已经添加源成功。如果成功则执行下列命令安装nginx yum install nginx rpm -qa | grep nginx #安装完后,查看 systemctl start nginx #动nginx systemctl enable nginx #入开机启动 ystemctl status nginx #看nginx的状态
在浏览器输入自己服务器的IP地址即可访问到nginx,如下图所示,nginx服务的默认端口为80(这里需要注意防火墙的限制和端口冲突)。
用命令lsof -i:80,可查看80端口被那个进程占用。
nginx服务的默认配置文件在 vim /etc/nginx/conf.d/default.conf ,打开可看到,默认端口为80,项目部署目录为/usr/share/nginx/html/。
向/usr/share/nginx/html/ 目录下上传一个JavaScript写的飞机大战。
在浏览器里输入http://192.168.0.146/Plane/test/,即可访问到。
第二种方法:
1.安装依赖包
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel gd-*
2.创建用户
useradd -s /sbin/nologin nginx
3.下载nginx-1 .1 4.2源码包
cd /usr/local/srcwget http://nginx.org/download/nginx-1.16.1.tar.gz
4. 解压nginx
tar -zxvf nginx-1.16.1.tar.gz
5.开始对nginx进行编译
mkdir -p /usr/local/nginx cd nginx-1.16.1 ./configure \ --prefix=/usr/local/nginx \ --lock-path=/usr/local/nginx/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module --with-http_flv_module \ --with-http_stub_status_module --with-http_gzip_static_module \ --http-client-body-temp-path=/usr/local/nginx/client/ \ --http-proxy-temp-path=/usr/local/nginx/proxy/ \ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi \ --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre \ --with-file-aio --with-http_image_filter_module
6.开始对nginx进行编译
make && make install
7.nginx的启动
nginx # 启动服务 nginx -s stop #关闭服务 nginx -s reload #重新加载配置文件 nginx -t #测试配置文件 nginx -v #查看版本信息 nginx -V #查看编译选项
8.测试nginx是否可以访问