Linux部署nginx

1.下载安装包

官网:http://nginx.org/
在这里插入图片描述
选中对应系统的安装包(版本没有需求就选中文档版本)
在这里插入图片描述

2.上传安装包

在这里插入图片描述

3.解压安装包

创建一个安装nginx目录
nginx-home : mkdir /usr/local/nginx

tar -xvf /home/eamshome/nginx脚本安装/nginx-1.20.2.tar.gz

4.检测安装

进入安装目录 cd /usr/local/nginx/nginx-1.20.2/
执行安装检测:./configure
检测没问题进行第5不安装。出现问题及解决方案如下:

  • C compiler cc is not found :没有gcc环境。
checking for OS
 + Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found

安装gcc解决 yum -y install gcc

  • error: the HTTP rewrite module requires the PCRE library. 没有pcre-devel环境。
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

安装pcre-devel解决 yum install pcre-devel

  • error: the HTTP gzip module requires the zlib library. 没有 zlib-devel环境。
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

安装zlib-devel解决 yum install zlib-devel

继续执行./configure , 出现如下提示即可进行第5不安装.

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  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"

5.安装

进入目录:cd /usr/local/nginx/nginx-1.20.2
执行: make
提示出现: 离开目录“/usr/local/nginx/nginx-1.20.2”代表指令运行结束
在这里插入图片描述
继续执行指令进行安装:make install
在这里插入图片描述
出现如下提示安装完成:
在这里插入图片描述

6.测试安装是否成功

进入安装目录:cd /usr/local/nginx
在这里插入图片描述
执行测试指令:./sbin/nginx -t

./sbin/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

在这里插入图片描述

7.启动nginx

nginx指令路径:cd /usr/local/nginx/sbin
启动nginx:./nginx

在浏览器中输入服务器的ip地址,如:http://192.168.187.128/
很不幸,打不开链接。下面进行原因排查:
使用dos窗口 ping 192.168.187.128
在这里插入图片描述
在这里插入图片描述
说明服务器的80端口是打不开的。

因为我使用的linux系统版本是CentOS7,所以可以在服务器中执行如下命令来验证
firewall-cmd --query-port=80/tcp
在这里插入图片描述
显然80端口没有开启。

下面我们开启80端口: firewall-cmd --add-port=80/tcp
在这里插入图片描述
刷新浏览器:
在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老攀呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值