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 ...
随机推荐
- 常用oracle可重复执行的脚本模板
为保证脚本的可重复执行以及丢失,涉及到数据库环境的移植等,就会使用可重复执行脚本,此处仅提供相关一些模板 说明下:该脚本需要在命令窗口执行,而不是在SQL窗口执行 创建序的脚本 /** * 作者:zk ...
- arch xfce快捷键
<Alt>F1:xfce4-popup-applicationsmenu 打开右键菜单 <Alt>F2:xfrun4 打开应用程序运行窗口,同<Alt>F3差不多 ...
- Github远程仓库提交代码步骤
1.克隆远程仓库 1)当没有设置默认目录时 git clone 仓库地址 本地存放目录 //没有目录的情况 2)当设置了本地存放目录时 先打开路径,命令: ...
- vue中 左侧导航条 多个toggleClass
<ul> <li v-for='item in items' @click="showToggle(item)"> <i :class="{ ...
- 2018-计算机系机试-A
#include<stdio.h> #include<cstdio> #include<cmath> #include<cstring> #includ ...
- CSV空行问题
当写入CSV时生成的数据会有空行如果加入 newline =‘’ 不会新增空行 writefile = open('result.csv','w',newline =‘’) 原贴 https://bl ...
- Linux中访问Apache报403错误处理方法
1.先说本地环境,脱离基础环境的解决策略都是耍流氓 (1)Linux:CentOS7.5 (2)Apache: Apache/2.4.6 (CentOS) (3)Apache的安装路径在 /usr/l ...
- 【Linux】comm指令
语法 comm [-123][--help][--version][第1个文件][第2个文件] 参数 -1 不显示只在第1个文件里出现过的列 -2 不显示只在第2个文件里出现过的列 -3 不显示只在第 ...
- SQL Server中的连接查询(内连接、外连接、交叉连接)
在数据库查询中,经常会用到两个有关联的表进行查询,需要把两个表中的数据按照某些条件查出来,这时就可以使用连接查询 连接查询分为三种:内连接.外连接和交叉连接 1. 内连接 内连接inner join ...
- linux 修改配色
PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ " ORvim ~/ ...