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

一、环境

操作系统版本: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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值