Nginx--安装&&配置文件
官网:http://nginx.org/en/download.html
nginx版本:1.18
一 安装
1 下载预编译环境(预编译报错需要安装什么库 直接在库名后面接 -devel 使用yum下载)
yum -y install pcre-devel openssl-devel gcc gcc-c++
2 创建用户,解压包
useradd -M -r -s /sbin/nologin nginx
tar xvf nginx-1.18.0.tar.gz
3 预编译
[root@localhost ~]# cd nginx-1.18.0/
[root@localhost nginx-1.18.0]# ./configure --with-http_realip_module --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module
编译选项
| --prefix=path | 指定安装路径,默认/usr/local/ |
| --sbin-path=path | 指定二进制命令的路径 |
--conf-path=path |
指定配置文件conf路径 |
| --error-log-path= | 指定错误日志error.log路径,默认/usr/local/nginx/logs/ |
| --http-log-path= | 指定主日志access.log路径 |
| --with-http_stub_status_module | 启用service status页,默认不启用 |
| --with-http_ssl_module | 启用ssl模块,以支持https请求 |
| --with-http_realip_module | 获取客户端真实ip时使用 |
4 编译安装
make && make install
5 命令
| /usr/local/nginx/sbin/nginx -s | 给主进程发送信号.可接 stop | quit | reopen | reload(不关闭服务重置配置文件) |
| /usr/local/nginx/sbin/nginx -t | 检查主配置文件有无错误 |
| /usr/local/nginx/sbin/nginx -v | 查看版本号 |
| /usr/local/nginx/sbin/nginx -V | 查看版本号及编译选项 |
| /usr/local/nginx/sbin/nginx -c | 指定配置文件,默认为 conf/nginx.conf |
#设置命令
ln -s /usr/local/nginx/sbin/* /usr/local/sbin
二 配置文件详解(/usr/local/nginx/conf/nginx.conf)
nginx配置文件主要分为五大块
全局块(main) 配置影响nginx全局的指令,一般有nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process等
events 配置影响nginx服务器与用户的网络连接,每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等
http 可以嵌套多个server 配置代理、缓存、日志定义等绝大多数功能和第三方模块的配置
server 配置虚拟主机的相关参数,一个httpd中可以有多个sercer
location 配置请求的路由,以及各种页面的处理情况
[root@localhost nginx]# cat /usr/local/nginx/conf/nginx.conf #user nobody; #nginx用户及组,如果用户和组名一样可只写一个,一般写作 user nginx;
worker_processes 1; #工作进程的数量,不要超过8,一般为cpu核数,不确定时设为auto(自动检测)最优值取决很多因素,包括但不限于CPU核的数量,存储数据的硬盘,数量及负载模式 #error_log logs/error.log; #错误日志的相关信息(级别 路径...)一般不用改动
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024; #每个进程的最大连接数,根据需要调整大小
} http {
autoindex on; #添加此行,访问目录下没有索引文件,则显示目录下所有内容
include mime.types; #文件扩展名与文件类型映射表(引用文件)
default_type application/octet-stream; #默认应用类型
server_tokens off; #添加此行,隐藏版本号 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' #定义访问日志格式
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; #定义日志文件(可以用include 路径/文件名) sendfile on; #开启高效文件传输模式
#tcp_nopush on; #必须在sendfile开启模式才有效,防止网路阻塞,积极的减少网络报文段的数量(将响应头和正文的开始部分一起发送,而不一个接一个的发送。) #keepalive_timeout 0;
keepalive_timeout 65; #连接超时时间,长连接,一般开启 #gzip on; #压缩传输 server { #http子块 每一个server都是一台虚拟主机
listen 80; #监听端口
server_name localhost; #虚拟主机域名
client_max_body_size 10M; #限制上传文件大小
#charset koi8-r; #字符集 #access_log logs/host.access.log main; #虚拟主机级别日志 location / { #url浏览器输入的路径
root html; #访问的目录/usr/local/nginx/html
index index.html index.htm; #索引文件
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #错误页面
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
三 location
语法 location [修饰符] /uri|pattern {...}
修饰符 = 精确匹配,优先级最高
^~ 前缀匹配,优先级高于正则匹配
~ 正则匹配,区分大小写
~* 正则匹配,不区分大小写
没有修饰符,优先级最低
注:
优先级的高低与location出现顺序无关
尽量使用单一的location修饰符去完成任务
如果uri为前缀目录,动作为proxy_pass 代理的IP后面有目录,前缀目录会被覆盖掉
root,alias指令
nginx指定文件路径有两种方式:root,alias,主要区别在于nginx如何解释location后面的uri
alias是一个目录别名的定义,root则是最上层目录的定义
使用alias时,目录名后面一定要加”/“
root处理结果:root路径+location路径
alias处理结果:alias路径
root:
语法: root path
默认值:root html
配置段:http server location
alias:
语法: alias path
配置段:location
例:
#访问uri:/test,实际访问的是 /tmp/html/test/index.html 这个文件
location /test {
root /tmp/html;
index index.html;
}
#访问uri:/test,实际访问的是 /tmp/html/index.html 这个文件
location /test {
alias /tmp/html/;
index index.html;
}
四 日志(内嵌变量)
更多内嵌变量参见:http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#variables
| $remote_addr | 记录直接与服务器通信的客户端的IP |
| $remote_user | 记录远程客户端的名字 |
| $time_local | 记录访问时间 |
| $request | 记录请求的URL(资源定位) |
| $status | 记录请求状态 |
| $body_bytes_sent | 记录发送给客户端的文件的内容的大小 |
| $http_referer | 记录从哪个页面链接访问过来的 |
| $http_user_agent | 记录客户端浏览器的信息 |
| $http_x_forwarded_for | 记录从请求报文首部的X-Forwarded-For字段获取的值 |
| $http_x_real_ip | 记录从请求报文首部的X-Real-IP字段获取值 |
| $realip_remote_addr | 最后一个反向代理服务器的IP |
Nginx--安装&&配置文件的更多相关文章
- Nginx 安装配置文件解析
源地址:https://www.cnblogs.com/Chiler/p/8027167.html 前言 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/P ...
- ubuntu nginx 安装以及配置文件详解
1.到nginx官网下载源码包.最好下载稳定版本,nginx官网http://www.nginx.org/ 2.安装nginx依赖包运行命令: sudo apt-get install libssl- ...
- 第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置
第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置 软件版本 uwsgi- ...
- Nginx安装及配置文件nginx.conf详解
1.安装Nginx 在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcre-devel和zlib-devel软件库. 下面是Nginx安装过程: wget http ...
- 01 - nginx - 安装、配置文件、默认网站、虚拟主机
一.运维: . 介绍服务器. 服务器逻辑: 服务器选择 操作系统 部署逻辑 业务环境部署逻辑 业务部署图 软件部署文档 日常维护文档 测试 开发上传代码到源码系统 上线 - 测服务器,内测 预发布测试 ...
- Nginx安装部署以及配置文件解析
Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令.Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的”/uri/”,可以是字符串或 ...
- Nginx安装及配置文件解释
安装nginx,还是在mac上面用brew比较方便. 首先,brew install nginx,提示改权限 sudo chown -R $(whoami) /usr/local 然后brew ins ...
- nginx安装及配置文件详解
一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...
- Nginx安装,目录结构与配置文件详解
1.Nginx简介 Nginx(发音同 engine x)是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设 ...
- Nginx安装与配置文件nginx.conf详解
引用“http://ixdba.blog.51cto.com/2895551/790611” 1.安装Nginx在安装Nginx之前,需确保系统已经安装了gcc. openssl-devel. pcr ...
随机推荐
- nordic的nrf52系列32M速率的SPI-SPIM3
简介:在nordic的nrf52系列中的nrf52833和nrf52840的SPIM3都是支持最大32M的spi速率,其余的只有8M,当在需要刷屏,或者一些需要高速32M-SPI时,这是一个很好的使用 ...
- 带圆角的虚线边框?CSS 不在话下
今天,我们来看这么一个非常常见的切图场景,我们需要一个带圆角的虚线边框,像是这样: 这个我们使用 CSS 还是可以轻松解决的,代码也很简单,核心代码: div { border-radius: 25p ...
- zookeeper JavaAPI 操作-watch监听
1.NodeCache监听代码: @Test public void testNodeCache() throws Exception { //1.创建NodeCache对象 NodeCache no ...
- Redis全文搜索教程之创建索引并关联源数据
Redis 全文搜索是依赖于 Redis 官方提供的 RediSearch 来实现的.RediSearch 提供了一种简单快速的方法对 hash 或者 json 类型数据的任何字段建立二级索引,然后就 ...
- 神经网络优化篇:详解其他正则化方法(Other regularization methods)
其他正则化方法 除了\(L2\)正则化和随机失活(dropout)正则化,还有几种方法可以减少神经网络中的过拟合: 一.数据扩增 假设正在拟合猫咪图片分类器,如果想通过扩增训练数据来解决过拟合,但扩增 ...
- 神经网络优化篇:详解归一化输入(Normalizing inputs)
归一化输入 训练神经网络,其中一个加速训练的方法就是归一化输入.假设一个训练集有两个特征,输入特征为2维,归一化需要两个步骤: 零均值 归一化方差: 希望无论是训练集和测试集都是通过相同的\(μ\)和 ...
- ubuntu 20.0.4 LTS 配置国内apt-get源
https://blog.csdn.net/wangyijieonline/article/details/105360138 更换阿里源 要知道当前系统的代号,可以用以下命令: lsb_releas ...
- Spring Boot与Shiro和Mybatis整合
1:shiro是什么? Apache Shiro 是ASF旗下的一款开源软件 shrio是一款强大而灵活的安全框架 可为任何应用提供安全保障- 从命令行应用.移动应用到大型网络及企业应用 2:shir ...
- vuepress借助jenkins和svn实现文档自动化更新部署
前言 有个需求,需要将放在SVN的用vuepress写的文档进行自动化更新和部署,每次有人在本地将写好的md文件更新到svn时候,由jenkins实现自动打包来实现自动更新的功能. docker安装j ...
- Cesium案例解析(十)——CZML点
目录 1. 概述 2. 案例 3. 结果 1. 概述 CZML是Cesium中用于描述动态图形场景的JSON格式,它们的关系类似于Google Earth与KML之间的关系,一般会认为KML是一种矢量 ...