CentOS7安装Nginx

6 篇文章 0 订阅
6 篇文章 0 订阅

查看CentOS版本:

cat /etc/redhat-release

[root@data1 nginx-1.14.0]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

最新稳定版Nginx地址:

http://nginx.org/download/nginx-1.14.0.tar.gz

1.下载Nginx:

wget http://nginx.org/download/nginx-1.14.0.tar.gz

[root@data1 application]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
--2018-07-24 20:04:48--  http://nginx.org/download/nginx-1.14.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2001:1af8:4060:a004:21::e3, ...
正在连接 nginx.org (nginx.org)|206.251.255.63|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1016272 (992K) [application/octet-stream]
正在保存至: “nginx-1.14.0.tar.gz”

100%[================================================================================================================================================================================================>] 1,016,272   25.8KB/s 用时 47s    

2018-07-24 20:05:36 (21.0 KB/s) - 已保存 “nginx-1.14.0.tar.gz” [1016272/1016272])

2.解压

tar zxvf nginx-1.14.0.tar.gz

[root@data1 application]# tar zxvf nginx-1.14.0.tar.gz

3.生成配置

3.1 先进入解压后的文件夹

[root@data1 application]# cd nginx-1.14.0

[root@data1 application]# cd nginx-1.14.0

3.2 生成配置

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
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

提示找不到C编译器

3.3 安装C编译器

[root@data1 nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make

[root@data1 nginx-1.14.0]# yum -y install gcc gcc-c++ autoconf automake make

等待安装完成

再执行生成配置的命令

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx
checking for OS
 + Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
checking for gcc -pipe switch ... found

...
省略
...

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

3.4 安装pcre

[root@data1 nginx-1.14.0]# yum install pcre

[root@data1 nginx-1.14.0]# yum install pcre

再执行生成配置的命令

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

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

[root@data1 nginx-1.14.0]# yum install pcre-devel

[root@data1 nginx-1.14.0]# yum install pcre-devel

再执行生成配置的命令

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

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

缺少gzip库

3.5 安装gzip

[root@data1 nginx-1.14.0]# yum install -y zlib-devel

[root@data1 nginx-1.14.0]# yum install -y zlib-devel

再执行生成配置的命令

[root@data1 nginx-1.14.0]# ./configure --prefix=/usr/local/nginx

creating objs/Makefile

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"

出现以上内容就表示检测通过了, 生成配置文件Makefile

3.6 编译安装

[root@data1 nginx-1.14.0]# make && make install

[root@data1 nginx-1.14.0]# make && make install
make -f objs/Makefile
make[1]: 进入目录“/application/nginx-1.14.0”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c

...
省略
...

make[1]: 离开目录“/application/nginx-1.14.0”

安装完毕!

3.7 启动Nginx服务并查看监听端口

[root@data1 nginx-1.14.0]# cd /usr/local/nginx/sbin/
[root@data1 sbin]# ./nginx 
[root@data1 sbin]# netstat -antp

[root@data1 nginx-1.14.0]# cd /usr/local/nginx/sbin/
[root@data1 sbin]# ./nginx 
[root@data1 sbin]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9869/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      530/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      783/master          
tcp        0      0 192.168.190.11:22       192.168.190.1:3794      ESTABLISHED 2573/sshd: root@pts 
tcp6       0      0 :::22                   :::*                    LISTEN      530/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      783/master

可以看出Nginx监听的是80端口

如果启动失败,可能是其他程序占用了80端口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CentOS7安装NGINX,你需要按照以下步骤进行操作: 1. 首先,你需要准备好安装NGINX的环境。这包括安装GCC编译器。使用以下命令安装GCC环境: ``` $ yum install -y gcc ``` 2. 下载NGINX安装文件。你可以从NGINX官方网站下载最新版本的NGINX压缩包。将下载好的文件解压缩: ``` $ tar -zxvf nginx-1.20.2.tar.gz ``` 3. 进入解压后的NGINX目录,执行以下命令编译和安装NGINX: ``` $ cd nginx-1.20.2 $ ./configure $ make $ make install ``` 4. 安装完成后,你可以通过以下命令启动NGINX服务: ``` $ nginx ``` 5. 在浏览器中访问服务器的IP地址或域名,你应该能够看到NGINX的欢迎页面,这表明NGINX已成功安装并正在运行。如果你想在系统启动时自动启动NGINX服务,可以执行以下命令: ``` $ systemctl enable nginx ``` 请注意,这里提供的步骤是一种常见的安装NGINX的方法,具体的步骤可能因个人系统环境而有所不同。如果你遇到任何问题,可以参考NGINX的官方文档或在相关技术社区寻求帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux操作系统CentOS7安装Nginx[详细版]](https://blog.csdn.net/Wei_Naijia/article/details/124228897)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Centos7安装配置nginx](https://blog.csdn.net/Siebert_Angers/article/details/126960866)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [centos7安装nginx1.16.1](https://download.csdn.net/download/readyoften/13093228)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值