nginx的功能特性、安装与常用命令

转载自 http://www.dtcms.cn/news/show-219.html

反向代理:
正向代理:代理客户端(如:VPN)
反向代理:代理服务器

Nginx负载均衡策略:
轮询、加权轮询

解决session不共享问题:
iphash:对客户端请求的ip进行hash操作,然后根据hash结果将同一个客户的请求分发给同一台服务器进行处理,可以解决session不共享的问题。
加Redis:

动静分离

下载:

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

在这里插入图片描述
windowins下安装并启动:
只需要解压到无中文路径即可,有中文会报错,
然后找到nginx.exe的地方,双击nginx.exe即可启动,但是会一闪而过,所以不建议这样启动,建议在此处打开cmd输入nginx.exe启动(注:start nginx 也可以,建议使用start nginx)(注意路径)。
在这里插入图片描述
默认监听80:
conf目录下的nginx.conf文件中默认监听拦截80端口,此端口根据实际情况去配置:

在这里插入图片描述
验证监听:
在浏览器随便输入一个80端口的请求,看到下面界面,说明监听成功。
在这里插入图片描述
linux下安装(略复杂)并启动:
1.解压:

tar -zxvf nginx-1.20.0.tar.gz //解压

在这里插入图片描述

2.解压以后执行命令: ./configure
注:由于linux安装不同,此处可能会出现缺失依赖库的错误,缺失什么安装什么后再次执行 ./configure即可,笔者安装时遇到三次错误:

a.

./configure: error: C compiler cc is not found

解决命令:yum -y install gcc gcc-c++ autoconf automake make
b.

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

解决命令:yum -y install pcre-devel
c.

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

解决命令:yum install -y zlib-devel

3.然后分别执行下面两个命令:

make //编译
make install //安装

4.启动
用 whereis nginx 查看nginx安装路径,然后进入路径位置,执行启动命令 ./nginx

在这里插入图片描述
验证:(与Windows相似)

在这里插入图片描述

注:如果访问不到可能是linux防火墙没有关闭,如何linux防火墙请参考下面文章:
链接: 虚拟机能请求到虚拟的web项目,宿主机却访问不了——linux关闭防火墙.

Nginx常用命令(linux下):


 1. cd /usr/local/nginx/sbin #进入命令目录
 2. ./nginx #启动
 3. ./nginx -s stop #强制退出
 4. ./nginx -s quit #安全退出
 5. ./nginx -s reload #重新加载配置文件
 6. ps aux|grep nginx #查看nginx进程

Nginx常用命令(windows下):
验证配置是否正确: nginx -t
查看Nginx的详细的版本号:nginx -V
查看Nginx的简洁版本号:nginx -v
启动Nginx:start nginx
快速停止或关闭Nginx:nginx -s stop
正常停止或关闭Nginx:nginx -s quit
配置文件修改重装载命令:nginx -s reload

详细配置: https://www.runoob.com/w3cnote/nginx-setup-intro.html.

**

nginx配置文件:

**

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值