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

简介: 一、环境操作系统版本:CentOS Linux release 7.4.1708 (Core) 最小化安装版二、安装过程1、安装编译工具及相关库。

一、环境

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

二、安装过程

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

[root@Geeklp-Nginx ~]# yum -y install gcc-c++ zlib-devel openssl-devel libtool

2、下载Nginx及PCRE。

[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。

[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。

[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。

[root@Geeklp-Nginx nginx-1.13.7]# /usr/local/share/applications/nginx-1.13.7/sbin/nginx

6、配置防火墙。

[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版本:

[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、检查配置是否正确。

[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、重载配置文件,配置防火墙。

[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。

[root@Geeklp-Nginx conf]# ../sbin/nginx -s stop

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

[root@Geeklp-Nginx conf]# ../sbin/nginx
[root@Geeklp-Nginx conf]# ../sbin/nginx -s reopen

8、查看帮助。

[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、配置开机启动。

[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

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

相关文章
|
4天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
22 0
|
4天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
15 0
|
1天前
|
关系型数据库 MySQL Java
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
Linux 安装 JDK、MySQL、Tomcat(图文并茂)
13 2
|
1天前
|
Oracle Java 关系型数据库
Linux环境安装配置JDK11
Linux环境安装配置JDK11
18 0
|
1天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
21 2
|
1天前
|
Ubuntu Linux
Linux(Ubuntu)系统临时IP以及静态IP配置(关闭、启动网卡等操作)
请注意,以上步骤是在临时基础上进行配置的。如果要永久保存静态IP地址,通常还需要修改 `/etc/network/interfaces`文件,以便在系统重启后保持配置。同时,确保备份相关配置文件以防止出现问题。
13 1
|
3天前
|
监控 安全 Linux
Linux系统之安装ServerBee服务器监控工具
【4月更文挑战第22天】Linux系统之安装ServerBee服务器监控工具
41 2
|
3天前
|
Ubuntu Linux 测试技术
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试(下)
Linux(32)Rockchip RK3568 Ubuntu22.04上部署 Docker: 详细配置与功能测试
35 1
|
3天前
|
运维 网络协议 Linux
Linux(28) Linux双网卡配置为连接到Linux主机的PC提供外网访问
Linux(28) Linux双网卡配置为连接到Linux主机的PC提供外网访问
31 1
|
3天前
|
Linux 开发工具 Android开发
Docker系列(1)安装Linux系统编译Android源码
Docker系列(1)安装Linux系统编译Android源码
7 0