linux 安装nginx

linux 安装nginx

环境准备:

(1)linux 内核2.6及以上版本:
只有2.6之后才支持epool ,在此之前使用select或pool多路复用的IO模型,无法解决高并发压力的问题。通过命令uname -a 即可查看。

#查看 linux 内核
uname -a  

(2)GCC编译器
GCC(GNU Compiler Collection)可用来编译C语言程序。Nginx不会直接提供二进制可执行程序,只能下载源码进行编译。
(3)PCRE库
PCRE(Perl Compatible Regular Expressions,Perl兼容正则表达式)是由Philip Hazel开发的函数库,目前为很多软件所使用,该库支持正则表达式。
(4)zlib库
zlib库用于对HTTP包的内容做gzip格式的压缩,如果我们在nginx.conf里配置了gzip on,并指定对于某些类型(content-type)的HTTP响应使用gzip来进行压缩以减少网络传输量。
(5)OpenSSL开发库
如果我们的服务器不只是要支持HTTP,还需要在更安全的SSL协议上传输HTTP,那么就需要拥有OpenSSL了。另外,如果我们想使用MD5、SHA1等散列函数,那么也需要安装它。
上面几个库都是Nginx 基础功能所必需的,为简单起见我们可以通过yum 命令统一安装。

  • yum 安装nginx环境
[root@hadoop100 ~]# cd /tmp/
#yum 安装nginx 环境
[root@hadoop100 tmp]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel

安装

  • 下载nginx 最新稳定版本
#下载nginx 最新稳定版本
[root@hadoop100 tmp]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
#解压
[root@hadoop100 tmp]# tar -zxvf nginx-1.20.1.tar.gz
[root@hadoop100 tmp]# cd /tmp/nginx-1.20.1

  • 安装
# 全部采用默认安装
[root@hadoop100 nginx-1.20.1]# ./configure
[root@hadoop100 nginx-1.20.1]# make && make install

执行完成之后 nginx 运行文件 就会被安装在 /usr/local/nginx 下。

  • 基于参数构建
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-debug
  • 启动 Nginx
[root@hadoop100 nginx-1.20.1]# cd /usr/local/nginx/
[root@hadoop100 nginx]# ./sbin/nginx

  • 查看
[root@hadoop100 nginx]# ps -ef|grep nginx
root       9595      1  0 13:06 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     9596   9595  0 13:06 ?        00:00:00 nginx: worker process
root       9608   4681  0 13:20 pts/4    00:00:00 grep --color=auto nginx
  • nginx启动后web访问

在这里插入图片描述

  • 常用命令
#默认方式启动:
./sbin/nginx 
#指定配置文件启动 
./sbing/nginx -c /tmp/nginx.conf 
#指定nginx程序目录启动
./sbin/nginx -p /usr/local/nginx/

#快速停止
./sbin/nginx -s stop
#优雅停止
./sbin/nginx -s quit

# 热装载配置文件 
./sbin/nginx -s reload
# 重新打开日志文件
./sbin/nginx -s reopen

自动安装脚本

 vim mynignx.sh
  • 复制以下内容
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel
cd /tmp/
wget http://nginx.org/download/nginx-1.20.1.tar.gz
cd /tmp/
tar -zxvf nginx-1.20.1.tar.gz
cd /tmp/nginx-1.20.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-debug
cd /tmp/nginx-1.20.1
make && make install
  • 执行权限
chmod +x mynignx.sh
  • 执行命令
./myningx.sh

nginx安全认证

#安装密码工具
yum install httpd-tools -y
#查看帮助信息
htpasswd --help
#生成密码文件 admin:admin
htpasswd -bc /usr/local/nginx/conf/nginxpasswd admin admin

#配置nginx.conf 
#http
#	server
#		local
			# 配置密码login admin:admin
            auth_basic          "Restricted";
            auth_basic_user_file /usr/local/nginx/conf/nginxpasswd;
  • 重新加载
./sbin/nginx -s reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值