当前位置:网站首页>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;
}
}
}
边栏推荐
- 人才近悦远来,望城区夯实“强省会”智力底座
- 3D panoramic model display visualization technology demonstration
- Common components of flask
- latex如何打空格
- [mysql] install mysql5.7
- 在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
- 强大的万年历微信小程序源码-支持多做流量主模式
- Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)
- leetcode刷题:栈与队列01(用栈实现队列)
- 杰理之、产线装配环节【篇】
猜你喜欢
Penetration tools - trustedsec's penetration testing framework (PTF)
Error in installing sharp
leetcode刷题:二叉树02(二叉树的中序遍历)
Learn white box test case design from simple to deep
实战项目笔记(一)——虚拟机的创建
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
人才近悦远来,望城区夯实“强省会”智力底座
RichView RichEdit SRichViewEdit PageSize 页面设置与同步
Big factories are wolves, small factories are dogs?
BPR(贝叶斯个性化排序)
随机推荐
收藏:存储知识全面总结
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
【级联分类器训练参数】Training Haar Cascades
人脸识别系统 —— OpenCV人脸检测
功利点没啥!
Items in richview documents
How to create a pyramid with openmesh
新版图解网络PDF即将发布
【Leetcode】最大连续1的个数
deb文件安装
小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
After adding cocoapods successfully, the header file cannot be imported or an error is reported in not found file
Halcon知识:三维重构的一个尝试
2022年高处安装、维护、拆除考题模拟考试平台操作
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration
网上开户是安全的吗?新手可以开炒股账户吗。
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
利用QEventLoop实现同步等待槽函数返回