前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux(RHEL7及CentOS7)下Nginx的安装与配置

Linux(RHEL7及CentOS7)下Nginx的安装与配置

作者头像
耕耘实录
发布2018-12-20 12:01:47
9280
发布2018-12-20 12:01:47
举报
文章被收录于专栏:耕耘实录

一、环境

操作系统版本:CentOS Linux release 7.4.1708 (Core) 最小化安装版

二、安装过程

1、安装编译工具及相关库。

代码语言:javascript
复制
[root@Geeklp-Nginx ~]# yum -y install gcc-c++ zlib-devel openssl-devel libtool

2、下载Nginx及PCRE。

代码语言:javascript
复制
[root@Geeklp-Nginx ~]# curl -C - -O http://mirrors.sohu.com/nginx/nginx-1.13.7.tar.gz
[root@Geeklp-Nginx ~]# curl -C - -O https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz

3、编译安装PCRE。

代码语言:javascript
复制
[root@Geeklp-Nginx ~]# tar -xvzf pcre-8.41.tar.gz
[root@Geeklp-Nginx pcre-8.41]# cd pcre-8.41
[root@Geeklp-Nginx pcre-8.41]# mkdir /usr/local/share/applications/pcre-8.41
[root@Geeklp-Nginx pcre-8.41]# ./configure --prefix=/usr/local/share/applications/pcre-8.41/
[root@Geeklp-Nginx pcre-8.41]# make && make install

4、编译安装Nginx。

代码语言:javascript
复制
[root@Geeklp-Nginx ~]# tar -xvzf nginx-1.13.7.tar.gz
[root@Geeklp-Nginx nginx-1.13.7]# cd nginx-1.13.7
[root@Geeklp-Nginx nginx-1.13.7]# ./configure --prefix=/usr/local/share/applications/nginx-1.13.7/ --with-http_ssl_module
[root@Geeklp-Nginx nginx-1.13.7]# make && make install

5、启动Nginx。

代码语言:javascript
复制
[root@Geeklp-Nginx nginx-1.13.7]# /usr/local/share/applications/nginx-1.13.7/sbin/nginx

6、配置防火墙。

代码语言:javascript
复制
[root@Geeklp-Nginx nginx-1.13.7]# firewall-cmd --permanent --add-port=80/tcp
[root@Geeklp-Nginx nginx-1.13.7]# firewall-cmd --reload

7、验证。 在浏览器中输入服务器地址:10.1.1.21。出现如下图所示则说明Nginx安装成功!

这里写图片描述
这里写图片描述

三、配置Nginx

1、查看Nginx版本:

代码语言:javascript
复制
[root@Geeklp-Nginx nginx-1.13.7]# /usr/local/share/applications/nginx-1.13.7/sbin/nginx -v
nginx version: nginx/1.13.7

2、修改配置文件,去掉以下几行的注释,此步骤主要用于测试配置文件修改是否正确。

这里写图片描述
这里写图片描述

3、检查配置是否正确。

代码语言:javascript
复制
[root@Geeklp-Nginx conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/share/applications/nginx-1.13.7//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/share/applications/nginx-1.13.7//conf/nginx.conf test is successful

4、重载配置文件,配置防火墙。

代码语言:javascript
复制
[root@Geeklp-Nginx conf]# ../sbin/nginx -s reload

[root@Geeklp-Nginx conf]# firewall-cmd --permanent --add-port=443/tcp
[root@Geeklp-Nginx conf]# firewall-cmd --reload

5、验证。在浏览器里输入https://10.1.1.21/

这里写图片描述
这里写图片描述

说明https配置已经生效,但是不能正常使用,如需正常使用还需进一步配置。此处暂不讨论。 6、停止Nginx。

代码语言:javascript
复制
[root@Geeklp-Nginx conf]# ../sbin/nginx -s stop

7、启动Nginx并再次重启Nginx。

代码语言:javascript
复制
[root@Geeklp-Nginx conf]# ../sbin/nginx
[root@Geeklp-Nginx conf]# ../sbin/nginx -s reopen

8、查看帮助。

代码语言:javascript
复制
[root@Geeklp-Nginx conf]# ../sbin/nginx -h
nginx version: nginx/1.13.7
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/share/applications/nginx-1.13.7//)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

9、配置开机启动。

代码语言:javascript
复制
[root@Geeklp-Nginx sbin] echo "/usr/local/share/applications/nginx-1.13.7/sbin/nginx">>/etc/rc.local
[root@Geeklp-Nginx sbin]# chmod u+x /etc/rc.d/rc.local

其他内容后期文章再进一步讨论。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年12月26日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、环境
  • 二、安装过程
  • 三、配置Nginx
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档