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 ...
随机推荐
- 手动调用run方法和普通方法调用没有区别
手动调用run方法和普通方法调用没有区别
- 微信小程序笑话小程序实践开发学习
首先做出笑话展示页面 1.修改app.json文件,在"pages"中添加一条 "pages/joke/joke",然后ctrl+s就可以自动创建joke文件夹 ...
- String与StringBuffer之间的转换
来源:http://www.oschina.net/code/snippet_2261089_47352 package demo; /* String与StringBuffer之间的转换 * Str ...
- Python 查看线程的进程id
import os from threading import Thread # from multiprocessing import Process def f1(n): print('1号',o ...
- ENVI5.3 影像重采样 和 tiff 保存
输入---之前用envi4.5处理后的2013分类影像---输出重采样的影像 直接在工具栏搜索 resize data---出来对话框, 这里有几种方法----sample line 指的行列号,可以 ...
- MySQLdb模块(数据库)
安装 pip install mysqlclient 连接数据库 db = MySQLdb.connect(host="IP",port=端口,user="账号" ...
- 2018-4-12 数学建模MATLAB常用的一些函数
一.求函数的极限问题 limit(fun,x,y,str) 意义:fun为所求极限的函数,x代表变量,y代表变量的极限值,str代表这个极限的类型,常用的参数是right,left. 如果是多个变量的 ...
- Mac 电脑终端上传项目到github上
1.安装Git 去官网自己研究(这个是很全的,也很详细:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b806 ...
- android 版本更新适配8.0,解决8.0手机无法更新自动安装apk
随着android 7.0的普及android 8.0的也逐渐流行起来,那么google对权限方面又有了新的修改.而且我发现在android8.0中除了一些bug,比如说:在小米6(Android 8 ...
- Measuring Text Difficulty Using Parse-Tree Frequency
https://nlp.lab.arizona.edu/sites/nlp.lab.arizona.edu/files/Kauchak-Leroy-Hogue-JASIST-2017.pdf In p ...