nginx1.14.0版本server、location、rewrite配置
server配置demo
在192.168.10.140(centos7)上修改:
/home/program/nginx/conf/nginx.conf 添加一个server
server {
listen 80; //监听一个80端口的应用
server_name www.joyce.com; //应用的虚拟域名或IP(比如localhost)都可
access_log logs/my_access.log
error_log logs/my_error.log
charset utf-8;
error_page 404 = @fallback404 //语法就是@开头 location /@fallback404 {
proxy_pass http://www.baidu.com; //当404错误发生时,服务降级处理
}
location / { //应用的根路径访问
root html/domain; //应用的静态资源文件所在路径
index index.html; // 如果访问根路径/,则访问页面index.html
deny all; //拒绝任何请求
allow all; //允许所有请求
}
}
cd /home/program/nginx/html
mkdir domain //应用的静态资源文件所在路径
cd domain
vi index.html //创建一个访问页面index.html
<h1>I'm Joyce! </h1>
cd /home/program/nginx/sbin
./nginx -s reload 重新启动
在windows本机上修改:
修改host文件,路径: c:\windows\system32\drivers\etc
添加虚拟域名: 192.168.10.140 www.joyce.com
浏览器访问: http://192.168.10.140 结果显示html页面内容:I'm Joyce!
location精准路径和一般路径的区别
nginx.conf里面的location配置, 精准匹配的优先级高于一般匹配 。
精准路径配置:
location = /jingzhun { //精准路径必须跟上root的文件夹路径/domain才可访问index.html
root html/domain; //应用的静态资源文件所在路径
index index.html; // 如果访问根路径/,则访问页面index.html
}
一般路径配置:
location /yiban { //一般路径无需跟上root的文件夹路径/domain即可访问index.html
root html/domain; //应用的静态资源文件所在路径
index index.html; // 如果访问根路径/,则访问页面index.html
}
uri前后都加上/或都不加/,精准匹配才优先于一般匹配。
location的rewrite配置
location /abc {
rewrite '/images/[a-z]3/(.*)\.(png|jpg)' /jack?file=$2.$3; #路径跳转。用索引第二位参数和索引第三位参数,索引从0开始。跳转到下一个url
} location /abc2 { #跳转到下一个url
root html;
try_files $uri /image404.html;
} location /images404.html {
return 404 "image not found exception"; #直接输出不存在
}
nginx1.14.0版本server、location、rewrite配置的更多相关文章
- nginx1.14.0版本https加密配置
修改host文件,为最后访问域名准备 C:\Windows\System32\drivers\etc host文件目录192.168.10.140 www.joyce.com 在最后添加这个自定义域名 ...
- nginx1.14.0版本location路径,多级文件目录配置,root与alias的配置区别
1.多级目录配置 多级目录是指像/html/mypage 等等配置: server { listen 80; server_name localhost; location = /page1/ { # ...
- nginx1.14.0版本location路径配置四种方式
假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问. 第一种:location /proxy/ { proxy_pass http:// 12 ...
- nginx1.14.0版本负载均衡配置
upstream配置: upstream upstream1 { server 192.168.10.130:8080; server 192.168.10.140:8080; #server 192 ...
- nginx1.14.0版本高可用——keepalived双机热备
nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...
- elementaryos5安装mysql5.7、php7.2、nginx1.14.0
一.mysql5.7 安装mysql5.7: sudo apt-get install mysql-server-5.7 查看安装的mysql版本: mysql -V 5.7版本mysql安装过程中以 ...
- Nginx1.14.0+ModSecurity实现简单的WAF
一.编译安装Nginx 1.安装依赖环境 $ yum -y install gcc-c++ flex bison yajl yajl-devel curl-devel curl GeoIP-devel ...
- 编译安装和apt安装Nginx1.14.0
安装依赖 yum -y install gcc gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre-devel 在Ubun ...
- nginx-1.12.0版本(编译安装)-自定义安装路径
nginx-1.12.0版本(编译安装)-自定义安装路径 安装路径:/application/nginx-1.12.0 1.前期准备 安装编译需要的gcc和gcc-c++ yum install -y ...
随机推荐
- java+jenkins+testng+selenium+ant
1.安装jdk7以上2.http://mirrors.jenkins-ci.org/windows/latest 下载最新的war包3.cmd命令在war包目录下执行:java -jar jenkin ...
- KeepAlive--高可用解决方案
原文地址https://segmentfault.com/a/1190000011078937 一:keepalive简述 一;高可用的解决方案 1)vrrp协议的实现keepalive 2)ais ...
- linux 常用命令及实例
转载:https://www.cnblogs.com/xiaoyafei/p/9163976.html 在linux中,绝大多数命令都参照 命令 选项 参数 选项:适用于调整命令的功能的 参数:指的是 ...
- jmeter链接数据库
1.下载jar包“mysql-connector-java-8.0.12”包放入lib文件中 2.启动jemeter,添加线程组 3.在线程组下添加 JDBC Connection Configura ...
- 微信小程序测试策略
一.测试前准备(环境搭建) 1.前端页面 微信Web开发者工具安装.授权测试用的微信号可预览和调试小程序... 可参考此文: 微信Web开发者工具-下载.安装和使用图解 2.管理后台 配置内网测试服务 ...
- VMware Ubuntu安装过程
一.下载Ubuntu镜像文件 1.到官网下载:http://www.ubuntu.com 2.百度云(16.4.6): 链接:https://pan.baidu.com/s/14IlVP--D5mtZ ...
- Oracle SQL Developer 连接数据库问题总结
一.使用scott用户登录的问题 说明:Oracle如果是初次使用用户,scott用户是没有解锁的.所以要先解锁.注:scott是个测试用户. 具体步骤: 1.在Dos命令下输入 sqlplus 可以 ...
- 2017 cinemachine
只有2017以上才可以使用~ 导入Asset store中的cinemachine,会在上方显示cinemachine.每创建一个虚拟摄像机,就会在主摄像机下创建组件 cinemachine Bra ...
- 一次奇妙的http请求之旅
TCP/IP不是一个协议,而是一个协议族的统称.里面包括IP协议.IMCP协议.TCP协议. 这里有几个需要注意的知识点: 互联网地址:也就是IP地址,一般为网络号+子网号+主机号 域名系统:通俗的来 ...
- cifX使用心得
一.注意事项: 1.xChannelIORead()第一次读取到数据是空的.2.系统安装cifX驱动之前一定先安装有uio模块和libpciaccess库:建议系统内核为3.X.X版本,测试版本为3. ...