当前位置:网站首页>ngnix基础知识
ngnix基础知识
2022-07-01 19:36:00 【Mwyldnje2003】
参考信息:https://www.kuangstudy.com/
nginx简介




正向代理和反向代理
安装在客户端的代理就是正向代理,例如使用vpn等
安装在服务器端的代理就是反向代理,
正向代理代理的对象是客户端,反向代理代理的对象是服务端

负载均衡
依次请求就是轮寻

iphash是解决sessio会话不共享的问题,确保某一客户请求数据始终是请求到一个固定的服务器上(不建议这样使用,建议中redis)

nginx安装
下载地址:https://nginx.org/en/download.html
windows环境下安装
windows将下载文件解压后即可直接使用
可以双击启动文件,也可以使用cmd命令启动

linux环境下安装
首先安装依赖环境
自动配置nginx


执行make进行构建

Linux中make, make install命令分别是什么,用法?
查看ngnix配置路径
启动ngnix


nginx常用命令

修改配置文件后就需要重新加载配置文件
防火墙开放端口

使用实战
配置文件
可进一步参考:Nginx配置使用详解



配置文件解释
########### 每个指令必须有分号结束。#################
#user administrator administrators; #配置用户或者组,默认为nobody nobody。
#worker_processes 2; #允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid; #指定nginx进程运行文件存放地址
error_log log/error.log debug; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
events {
accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
#use epoll; #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 1024; #最大连接数,默认为512
}
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain
#access_log off; #取消服务日志
log_format myFormat ‘ r e m o t e a d d r – remote_addr– remoteaddr–remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for’; #自定义格式
access_log log/access.log myFormat; #combined为日志格式的默认值
sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。
upstream mysvr {
server 127.0.0.1:7878;
server 192.168.10.121:3333 backup; #热备
}
error_page 404 https://www.baidu.com; #错误页
server {
keepalive_requests 120; #单连接请求上限次数。
listen 4545; #监听端口
server_name 127.0.0.1; #监听地址
location ~*^.+$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
#root path; #根目录
#index vv.txt; #设置默认页
proxy_pass http://mysvr; #请求转向mysvr 定义的服务器列表
deny 127.0.0.1; #拒绝的ip
allow 172.18.5.54; #允许的ip
# expires 设置客户端缓存
#expires 1h;
index index.php index.html;
# 资源重定向,如访问http://shop.devops.com/index.html后会被重写为访问http://shop.devops.com/index.php,permanent表示永久重定向
rewrite /index.html /index.php permanent;
# 资源重定向,$request_filename为nginx的内置变量,表示资源文件路径
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.(js|css|jpg|png) {
# 告诉客户端所有js,css,jpg,png文件都可以缓存1小时,不用重新在服务器下载
expires 1h;
# 防盗链实现,所有不是从shop.devops.com跳转过去访问js|css|jpg|png文件的都被拦截,返回404
valid_referers shop.devops.com;
if ($invalid_referer) {
return 404;
}
}
# php解析
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
边栏推荐
- 寫博客文檔
- 大厂做狼,小厂做狗?
- RichView RichEdit SRichViewEdit PageSize 页面设置与同步
- 联想电脑怎么连接蓝牙耳机?
- Architect graduation summary
- What else do you not know about new set()
- STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
- EDA工具对芯片产业的重要性知识科普
- 人才近悦远来,望城区夯实“强省会”智力底座
- Entering Ruxin Town, digital intelligence transformation connects "future community"
猜你喜欢

【Opencv450】HOG+SVM 与Hog+cascade进行行人检测

杰理之、产线装配环节【篇】

NSI脚本的测试
![[multithreading] lock strategy](/img/97/5cacfd2de73d3c3b8acabf6b5c5ce3.png)
[multithreading] lock strategy

以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌

Importance of EDA tools to chip industry knowledge popularization

PLC模拟量输入 模拟量转换FB S_ITR(三菱FX3U)

300 linear algebra Lecture 4 linear equations

Common components of flask

2022安全员-A证考题及在线模拟考试
随机推荐
internship:逐渐迈向项目开发
利用QEventLoop实现同步等待槽函数返回
300题线性代数 第四讲 线性方程组
leetcode刷题:二叉树03(二叉树的后序遍历)
Error in installing sharp
Kuberntes云原生实战一 高可用部署架构
走进如心小镇,数智化变革连接“未来社区”
EMC-电路保护器件-防浪涌及冲击电流用
Develop those things: easycvr platform adds playback address authentication function
RichView TRVDocParameters 页面参数设置
Internship: gradually moving towards project development
多个张量与多个卷积核做卷积运算的输出结果
杰理之、产线装配环节【篇】
强大的万年历微信小程序源码-支持多做流量主模式
Principle of motion capture system
GCC编译
芭比Q了!新上架的游戏APP,咋分析?
Face recognition system opencv face detection
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
【级联分类器训练参数】Training Haar Cascades