网站首页 > 技术教程 正文
Nginx安装配置
1. Nginx下载安装
参考本人这篇文章:https://dpb-bobokaoya-sm.blog.csdn.net/article/details/106228804
2. Nginx配置文件
指令大全:http://nginx.org/en/docs/dirindex.html
以core模块的server指令为例:
Syntax: server {…}
Default: 一
Context: http
Syntax代表语法规则,Default代表默认值,Context代表在哪个模块中使用。
规则:
- 用〃#"表示注释
- 每行配置的结尾需要加上分号(漏了分号会导致无法启动)
- 如果配置项值中包括语法符号,比如空格符,那么需要使用单引号或双引号括住配置项值,否则Nginx会报语法错误
- 单位简写,当指定空间大小时,可以使用的单位包括: K或者k(千字节 KiloByte KB),M或者m(兆字节 MegaByte MB)比如
gzip_buffers 48k; client_max_body_size 64M;
??当指定时间时,可以使用的单位包括:ms (毫秒),s (秒),m (分钟),h (小 时),d (天),w (周,包含7天),M (月,包含30天),v (年,包含365天)。
例如
expires 10y;
proxy_read_timeout 600;
client_body_timeout 2m;
- 基本配置项
#user administrator administrators; #配置用户或者组,默认为 nobody nobody。
#worker_processes 2;#允许生成的进程数,默认为1
#pid /nginx/pid/nginx.pid; #指定 nginx 进程运行文件存放地址
error_log log/error.log debug;#制定日志路径,级别。这个设置可以放入全局块,http 块,server 块,级别以此为∶ debug|infolnotice|warn|error|crit|alertlemerg
events{
accept_mutex on; #设置网络连接序列化,防止惊群现象发生,默认为 on multi
accept on; #设置一个进程是否同时接受多个网络连接,默认为 off
#use epoll;#事件驱动模型,selectpollkqueuelepoll|resig|/dev/polleventport
worker_connections 1024;#最大连接数,默认为 512
}
http {
include mime.types;#文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为 text/plain
#access_log off; #取消服务日志
log_format myFormat '$remote_addr-$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
}
}
}
3.Nginx基本命令
在sbin目录下,加上./
4.Nginx 日志
4.1 日志路径和内容
??如果我们需要知道Nginx转发的请求的情况,比如来源IP、访问的URL、终端类型 等等,可以在Nginx中记录访问日志。如果Nginx运行发生了异常,也可以通过异常日 志找到原因。
??日志路径在安装根路径logs目录下。日志主要有两种,access.log是访问日志, error.log是服务错误日志。access日志的内容格式是可以定制的。
4.2 日志配置
配置文件:nginx-reverse.conf
log_format main'$remote_user[$time_local] $http_x_Forwarded_for $remote_addr $request‘
'$http_x_forwarded_for '
'$upstream_addr '
‘ups_resp_time: $upstream_response_time‘
‘request_time: $request_time \n';
配置了日志内容格式之后,继续配置日志:
可以使用的变量:
access_log path [format [buffer=size] [gzip[=level]] [flush=time][i仁condition]];
总结一下,主要的模块是access log. Iog_format.
猜你喜欢
- 2024-10-10 Nginx教程从入门到精通-nginx安装
- 2024-09-11 如何快速掌握Nginx 安装与配置?这个方法可能有用!
- 2024-09-11 nginx-安装与启动(nginx安装和配置)
- 2024-09-11 运维基础服务篇:Nginx概述和安装(nginx应用与运维实战pdf百度云)
- 2024-09-11 Nginx从安装到高可用,一篇搞定(nginx安装和使用)
- 2024-09-11 如何在linux中安装Nginx(如何在linux中安装python)
- 2024-09-11 Nginx安装配置学习(nginx1.16安装)
- 2024-09-11 新手学习第二阶段:Nginx服务安装配置及实战演练
- 2024-09-11 安装nginx(安装nginx涉及环境变量嘛)
- 2024-09-11 Nginx的安装、配置文件详解以及基本应用
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)