linux中部署安装nginx

nginx简介

nginx是一款高薪能的Http反向代理服务器
nginx的优点

1.高并发量:根据方管给出的数据,能过支持高达5万个并发连接数的响应
2.内存消耗少:处理静态文件,同样起web服务,比apache占用更少的内存及资源,所以它是轻量级的
3.简单稳定:配置简单,基本在一个conf文件中配置,性能比较稳定,可以7*24小时长时间不间断运行
4.模块化程度高:Nginx是高度模块化的设计,编写模块相对简单
5.负载均衡服务器:Nginx可以做高并发的负载均衡,且Nainx是开源免费的,如果使用F5等硬件来做负载均衡,硬件成本比较高
6.搞可移植性搞:Nginx代码完全用C语言编写

Nginx的缺点:

1.动态处理差:nginx处理静态文件好,耗费内存好,但是处理动态页面比较差
2.rewrite弱:虽然nginx支持rewrite功能,但是相比于apache来说,Apache比nginx的rewrite强大

编译安装nginx:

安装gcc编译环境

[root@xjm ~]# yum -y install gcc-c++

安装zlib-devel库

[root@xjm ~]# yum -y install zlib-devel

安装OpenSSL密码库

[root@xjm ~]# yum install -y openssl openssl-devel

安装pcre正则表达式

1.下载一个最新版本的pcre的压缩包
**下载地址:https://ftp.pcre.org/pub/pcre**

2.上传到服务器进行解压

[root@xjm ~]# tar -xf pcre-8.44.tar.gz 

3.进入pcre解压后的目录
cd pcre-8.44
4.创建一个安装路径

mkdir  -p /usr/local/pcre

5.指定安装路径

[root@xjm pcre-8.44]# ./configure --prefix=/usr/local/pcre/

6.安装

make &&make install

下载nginx

nginx下载官网:http://nginx.org./en/download.html

上传到服务器进行解压
或者也可以使用wget命令

[root@xjm opt]# wget http://nginx.org./download/nginx-1.20.1.tar.gz

下载完成之后,进入解压路径

[root@xjm opt]# tar -xf nginx-1.20.1.tar.gz 
[root@xjm opt]# cd nginx-1.20.1

> **创建安装目录**

[root@xjm nginx-1.20.1]#mkdir -p /usr/local/nginx

运行./configure文件

[root@xjm nginx-1.20.1]#./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre

编译安装

[root@xjm nginx-1.20.1]# echo $?
0
[root@xjm nginx-1.20.1]# make && make install

安装完成之后,进入/usr/local/nginx,查看是否安装成功。

[root@xjm nginx-1.20.1]# cd /usr/local/nginx
[root@xjm nginx]# ll
total 4
drwxr-xr-x. 2 root root 4096 Sep 11 02:16 conf
drwxr-xr-x. 2 root root   40 Sep 11 02:16 html
drwxr-xr-x. 2 root root    6 Sep 11 02:16 logs
drwxr-xr-x. 2 root root   19 Sep 11 02:16 sbin
[root@xjm nginx]# 

启动nginx

[root@xjm nginx]# cd sbin/
[root@xjm sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@xjm sbin]# 
[root@xjm sbin]# 
[root@xjm sbin]# ps -ef | grep nginx
root      48580   1449  0 02:19 pts/0    00:00:00 grep --color=auto nginx
[root@xjm sbin]# 

启动方法二

[root@xjm sbin]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@xjm sbin]# ps -ef | grep nginx                  root      48586   1449  0 02:20 pts/0    00:00:00 grep --color=auto nginx
[root@xjm sbin]# 

停止nginx服务

1.   ./nginx -s stop


2.    /usr/local/nginx/sbin/nginx -s stop

测试nginx语法是否正确

[root@xjm conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@xjm conf]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值