当前位置:网站首页>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;
}
}
}
边栏推荐
- 合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
- 小鸟逃票登机,如何反思,应如何解决,飞机为何怕小鸟?
- Oracle deadlock test
- Big factories are wolves, small factories are dogs?
- On the next generation entrance of the metauniverse -- the implementation of brain computer interface
- 强大的万年历微信小程序源码-支持多做流量主模式
- 股票手机开户哪个app好,安全性较高的
- 3D panoramic model display visualization technology demonstration
- Error in installing sharp
- Importance of EDA tools to chip industry knowledge popularization
猜你喜欢
随机推荐
【let var const】
Flask 常用组件
BPR(贝叶斯个性化排序)
合成大西瓜小游戏微信小程序源码/微信游戏小程序源码
强大的万年历微信小程序源码-支持多做流量主模式
关于new Set( )还有哪些是你不知道的
300题线性代数 第四讲 线性方程组
安装mysql时出现:需要这两个包perl(Data::Dumper),perl(JSON)
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
Past and present life of product modular design
以飞地园区为样本,看雨花与韶山如何奏响长株潭一体化发展高歌
利用QEventLoop实现同步等待槽函数返回
想请教一下,券商选哪个比较好尼?本人小白不懂,现在网上开户安全么?
How can I know if I want to get the preferential link of stock account opening? Is it safe to open an account online?
Summary of SQL aggregate query method for yyds dry goods inventory
新版图解网络PDF即将发布
Common components of flask
PHP 读取ini或env类型配置
EURA eurui E1000 series inverter uses PID to realize the relevant parameter setting and wiring of constant pressure water supply function








