YUM 安装
1.下载nginx包
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.建立nginx的yum仓库
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
3.下载并安装nignx
yum install nginx
4.启动nginx服务
systemctl start nginx
5.如果在浏览器中输入部署nginx环境的IP不能访问,可能是端口没有开启
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
systemctl stop firewalld.service systemctl start firewalld.service
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
源码编译安装
下载 Nginx 安装包
访问 ,这里下载固定版本:wget http://nginx.org/download/nginx-1.14.2.tar.gz
。
检查是否已经YUM安装
如果已安装,使用 yum remove nginx
命令删除。
➜ ~ yum list installed | grep nginxnginx.x86_64 1:1.12.2-2.el7 @epelnginx-all-modules.noarch 1:1.12.2-2.el7 @epelnginx-filesystem.noarch 1:1.12.2-2.el7 @epelnginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 @epelnginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 @epelnginx-mod-http-perl.x86_64 1:1.12.2-2.el7 @epelnginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 @epelnginx-mod-mail.x86_64 1:1.12.2-2.el7 @epelnginx-mod-stream.x86_64 1:1.12.2-2.el7 @epel
安装 Nginx
# 解压缩➜ tar -xvf nginx-1.14.2.tar.gz# 进入解压后的文件夹➜ cd nginx-1.14.2# 检查环境依赖,最后会提供如下的配置信息➜ ./configure# 编译安装➜ make && make install
./configure
执行后提示的 nginx 配置信息:
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"
运行 Nginx
/usr/local/nginx
中包含四个主要的目录:
conf:配置文件html:默认的 nginx 访问路径logs:各种日志信息sbin:二进制启动脚本
# 运行 nginx/usr/local/nginx/sbin/nginx# 查看运行进程ps -ef | grep nginx