当前位置:网站首页>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;
}
}
}
边栏推荐
猜你喜欢
朋友圈社区程序源码分享
深度学习 常见的损失函数
人才近悦远来,望城区夯实“强省会”智力底座
2022安全员-B证考试练习题模拟考试平台操作
在技术升级中迎合消费者需求,安吉尔净水器“价值战”的竞争之道
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
Use Zadig to build a continuous delivery platform from 0 to 1
leetcode刷题:二叉树01(二叉树的前序遍历)
Past and present life of product modular design
喜马拉雅自研网关架构演进过程
随机推荐
[Mysql]安装Mysql5.7
8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide
随机头像大全,多分类带历史记录微信小程序源码_支持流量主
leetcode刷题:栈与队列03(有效的括号)
Target detection - Yolo series
Swiftui 4 new features complete toggle and mixed toggle multiple binding components
[mysql] install mysql5.7
Data analysts sound tall? Understand these points before you decide whether to transform
Summary of SQL aggregate query method for yyds dry goods inventory
三菱PLC FX3U脉冲轴点动功能块(MC_Jog)
Architect graduation summary
大厂做狼,小厂做狗?
Niuke programming question -- must brush the string of 101 (brush the question efficiently, draw inferences from one instance)
个人炒股怎样开户?安全吗。
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌
目標檢測——Yolo系列
深度学习 神经网络基础
GCC编译
2022年高处安装、维护、拆除考题模拟考试平台操作
Customize the insertion of page labels and realize the initial search of similar address books