Nginx(二):Nginx基本安装

本文详细介绍了在Linux环境下,具体为CentOS7中,从环境准备到安装Nginx1.9版本的全过程。涵盖了gcc、PCRE库、OpenSSL库、zlib库的安装,以及Nginx的下载、编译、安装步骤,并提供了检测安装是否成功的方法和Nginx的基本命令操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于Linux安装

环境准备

  • CentOS7  
  • Nginx1.9
  • gcc gcc-c++
  • PCRE库
  • OpenSSL库
  • zlib库

基本安装

1.安装gcc gcc-c++

安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境

$ yum install -y gcc gcc-c++
2.安装wget(如未安装,请先安装)
$ yum -y install wget
3.安装PCRE库

PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。

$ cd /usr/local/
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
$ tar -zxvf pcre-8.33.tar.gz
$ cd pcre-8.33
$ ./configure
$ make && make install
4.安装OpenSSL库

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http)

$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.1j
$ ./config
$ make && make install
5.安装zlib库

zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip

$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make && make install
6.安装nginx
$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.9.0.tar.gz
$ tar -zxvf nginx-1.9.0.tar.gz
$ cd nginx-1.9.0 
$ ./configure
$ make && make install
7.检测是否安装成功
$ cd  /usr/local/nginx/sbin
$ ./nginx -t

Nginx常用命令

1.显示帮助信息
$ /usr/local/nginx/sbin/nginx -h

帮助信息如下:

Options:
  -?,-h         : this help  (显示帮助信息)
  -v            : show version and exit  (打印nginx版本,编译信息等)
  -V            : show version and configure options then exit  (打印nginx版本,编译信息等)
  -t            : test configuration and exit  (检测语法)
  -q            : suppress non-error messages during configuration testing
#发送信号(立刻停止stop、优雅停止quit、重载配置文件reload、重新开始记日志reopen)
-s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) (指定运行目录) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
2.启动nginx
$ /usr/local/nginx/sbin/nginx
3.查看进程
$ ps -aux | grep 'nginx'
 4.停止 Nginx
$ /usr/local/nginx/sbin/nginx -s quit    #发送信号方式 优雅停止quit$ /usr/local/nginx/sbin/nginx -s stop    #发送信号方式 立刻停止stop
5.Nginx 重载配置
$ /usr/local/nginx/sbin/nginx -s reload  #发送信号方式 立刻停止stop
 

 

转载于:https://www.cnblogs.com/kongliuyi/p/11494746.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值